def scatter_plot_sort(M,Label,sort, delta=100): x = [] y = [] print Label count = 0 yf = np.zeros((delta)) new_label = [] for j,i in enumerate(M): if Label[j] == sort: new_label.append(Label[j]) if i[1][0] < 0.5: x.append(i[0]) y.append(i[1]*5.) else: x.append(i[0]) y.append(i[1]) yf += y[count][0:delta] count+=1 yf = yf/len(new_label) new_label.append('average') print len(x[0]) x.append(x[0][0:delta]) y.append(yf) pyplot.plot(x[0][0:delta],yf,'average',logx=True,limx=(0,100),limy=(0,1),save='average') Mark = ['x','x','o','o','v','v','1','1','8','8','D','D'] Mark = ['x','x','o','o','v','1','1','8','8','D','D'] pyplot.plot_multi(x,y,new_label,logx=True,limx=(0,100),limy=(0,1),loc=1,make_marker=True,M=Mark, showleg=True,save='kowasaki_%s'%sort) fid = open('intstat_avg_%s.dat'%sort,'w') for j in range(yf.shape[0]): fid.write(('%.2f %.4f\n'%(x[0][j],yf[j]))) fid.close()
def type_ordering(VW,L): N = VW.shape[1]*8 order = [] count = 0 for k in range(VW.shape[0]): print k print count count = 0 for i in range(VW.shape[1]): NN=count_neighbors_index(VW[k],i,L[k],count=8)[0] NN.sort() if i < VW.shape[1]/2: for j in NN: if j >= VW.shape[1]/2: count+=1 if i >= VW.shape[1]/2: for j in NN: if j < VW.shape[1]/2: count+=1 order.append(count/float(N)) x = range(VW.shape[0]) fid = open('typeorder.txt','w') for i in range(len(order)): fid.write(('%i %.2f\n'%(i,order[i]))) fid.close() pyplot.plot(x,order, xlabel='time',ylabel='ordering',save='typeorder')
def structure_factor(VW, L, n_frames=10, n_start=1, filters=0.05, dh=0.05,save='sf'): import MD.analysis.sfactor as sf #Find Structure Factor stmp,qx = sf.sfactor(VW[n_start:n_start+n_frames],L=L,l=20) S,Q,primitive_vectors = sf.sort_sfpeaks(stmp,qx) #Plot the graph xlabel = '$|\\vec{q}$ $|$' ylabel = '$S(\\vec{q}$ $)$ ' pyplot.plot(Q, S, linestyle='', marker='x', xlabel=xlabel, ylabel=ylabel, save=save) util.pickle_dump(Q,'Vsfx%i.pkl'%n_start) util.pickle_dump(S,'Vsfy%i.pkl'%n_start) #if len(QQ)>500: # bars,height = sf.sf_max(QQ,qpeaks=8) # db_x,db_y = sf.dbfactor(msdr=5) # pyplot.plot_bar(bars, height, xlabel=xlabel, ylabel=ylabel, # save=save) # pyplot.plot(db_x, db_y, linestyle='--', xlabel=xlabel, ylabel=ylabel, # save=save) # #return q, s, bars, height, db_x, db_y # return Q, S, primitive_vectors #filter out the noise Q, S, primitive_vectors = sf.sf_filter(Q, S, primitive_vectors, filters=filters, save = 'sf%i'%n_start) return Q, S, primitive_vectors
def msd(VW,L,step=1): from MD.analysis.msd import msd #Find the msd of the system x,msd=msd(VW,L,step=step) print x print msd pyplot.plot(x,msd,xlabel='time',ylabel='msd',save='MSDtime') util.pickle_dump(msd,'msd.pkl')
def run_blah2(): dirname = os.getcwd().partition('/')[-1] print "Starting:",dirname.split('/')[-1] M=MD.ReadCord() Lx = M.box_length Ly = M.box_length_y Lz = M.box_length_z L = np.array([Lx, Ly, Lz]) surface = util.pickle_load('surface.pkl') fid = open('large.xyz','r') M = readxyz.ReadCord(trajectory = 'large.xyz',frames = 777) crystal = M.cord_auto(['V','W']) ########################### bcc = np.zeros((777,432,1)) for k in range(bcc.shape[0]): for i in range(bcc.shape[1]): if crystal[k][i][0] > L[0]: bcc[k][i]=0 else: bcc[k][i]=1 crystal = [] for k in range(len(bcc)): c=[] for i in range(len(bcc[k])): if bcc[k][i] == 1: c.append(i) crystal.append(len(c)) s = [] for k in range(len(surface)): surf = [] for i in range(len(surface[k])): if surface[k][i]: surf.append(i) s.append(surf) util.pickle_dump(s,'surface_diffusion.pkl') util.pickle_dump(crystal,'crystal_diffusion.pkl') lamda=4 D=0.05 ns = [] dt = 10 dmdt = [] C = lamda**2/(D*24) start = 100 finish = 350 for k in range(start,finish,dt): n = 0 for i in range(dt): n += len(s[i+k]) ns.append(n/dt) count = 0 for i in range(start,finish,dt): dm = crystal[i]-crystal[i-dt] dmdt.append(C*dm/ns[count]) count += 1 x = np.arange(start,finish,dt) pyplot.plot(x,dmdt,save='diffusion')
def find_lifetime(M): import MD.analysis.lifetime as lifetime conn = _connections(M) life = [] for i in range(3): life.append(lifetime.lifetime(conn[i:])[:len(conn)-3]) life_avg = [] for i in range(len(life[0])): avg = 0 for j in range(len(life)): avg += life[j][i]/float(len(life)) life_avg.append(avg) pyplot.plot(range(len(life_avg)),life_avg,xlabel='Time', ylabel='remain connections', save='lifetime')
def crystal_msd(VW,surface,L): #skip = VW.shape[0]/len(surface) skip = 1 index = [] for i in range(len(surface[0])): count = 0 for t in range(15): count += surface[t][i] if count >= 11: index.append(i) spheres = np.zeros((len(surface),len(index),3)) for f in range(len(surface)): for i in range(len(index)): spheres[f][i] = VW[f*skip][index[i]] x, MSD = msd_no_drift(spheres,L) pyplot.plot(x,MSD,xlabel='time',ylabel='msd cn',save='msd_critical')
def find_networks(M, VW, L, n_finish=1, n_start=0, delta=30, rcut=1.0, ndna=25): #The total number of frames we are going to look at x=np.arange(n_start,n_finish,delta) print len(x) #Find the number of connections at specific points x import MD.canalysis.connections as con import MD.analysis.connections as conn import MD.analysis.graph as graph try: connections = util.pickle_load('con.pkl') except: try: C = util.pickle_load('C.pkl') G = util.pickle_load('G.pkl') except: G=M.cord_auto(['G']) C=M.cord_auto(['C']) util.pickle_dump(C,'C.pkl') util.pickle_dump(G,'G.pkl') connections = con.connections(C[x],G[x],L,rcut=rcut) util.pickle_dump(connections,'con.pkl') #plot total number of connections num_connections=conn.num_connections(connections,VW.shape[1]) con_all = [] for i in range(len(connections)): con_all.append(len(connections[i])/2.) pyplot.plot(x,num_connections,xlabel='Time', ylabel='hyrbid. density', save='connections') pyplot.plot(x,con_all,xlabel='Time', ylabel='hyrbid', save='connections_all') plt.close() #get the info networks, num_networks, deg, neighbors, num_n, gr = graph.grapher(connections,VW.shape[1],ndna) util.pickle_dump(networks,'net.pkl') #plot the number of neighbors at each timesteps pyplot_eps.plot(x,num_n,xlabel='Time', ylabel='num neighbors', save='neighbors') plt.close() print 'making plot' net = [] for i in networks: net.append(len(i)) pyplot_eps.plot(x,net,xlabel='t',ylabel='networks',save='net') label = ['networks','1','2','3','4','5','6','7','8','9'] pyplot_eps.plot(x,networks,xlabel='t',ylabel='Networks',save='net') pyplot.plot_multi(x,deg,label,xlabel='time',ylabel='number',save='con_net') return x, networks, connections
def mylog(row = 2): #read log file import re fid = open('mylog.log','r') text = fid.readlines() fid.close() #loop through and pull out values we want x = [] y = [] for line in text[1:]: x.append(line.split()[0]) y.append(line.split()[row]) #make a simple plot label = re.sub("_"," ",text[0].split()[row]) save = text[0].split()[row] pyplot.plot(x, y, xlabel='Time', ylabel=label, save=save) return x, y
def msd(VW,L,step=1,save='MSD_time',time_scale=1): from MD.analysis.msd import msd_no_drift #Find the msd of the system x,msd=msd_no_drift(VW,L,step=step) D=0.1 D2=0.03 tau=10 try: M = util.pickle_load('msd.pkl') x = M[0][0] msd = M[1][0] except: x, msd = msd_no_drift(VW,L) x = x*time_scale util.pickle_dump([[x],[msd]],'msd.pkl') #msd_fit fit = [] for i in x: fit.append((2*3*D2*(i) - tau*(1-math.e**(-i/tau)))**0.5) msd2 = (6*D*x)**0.5 pyplot.plot(x,msd,xlabel='Time',ylabel='msd',save=save)
def projection_jump(VW,surface,proj,L,k,save='proj_hist'): #skip = VW.shape[0]/len(surface) skip = 1 jump_d = [] print len(surface) print VW.shape print proj.shape try: for i in surface: n, dist = close_neighbors_point(proj,VW[i],L) jump_d.append(dist) except: for i in surface: n, dist = close_neighbors_point(proj,VW[i-VW.shape[0]],L) jump_d.append(dist) print jump_d hist_s,xs=histogram_reg(jump_d,bins=10) pyplot.plot(xs,hist_s,xlabel='distance',ylabel='count',save=save) return jump_d
def structure_factor(VW, L, n_frames=10, n_start=1, filters=0.05, dh=0.05,save='sf',l=10): import MD.analysis.sfactor as sf #Find Structure Factor #Average_position stmp,qx = sf.sfactor(np.array([VW]),L=L,l=l) S,Q,primitive_vectors = sf.sort_sfpeaks(stmp,qx) #Plot the graph xlabel = '$|\\vec{q}$ $|$' ylabel = '$S(\\vec{q}$ $)$ ' pyplot.plot(Q, S, linestyle='', marker='x', xlabel=xlabel, ylabel=ylabel, save=save) util.pickle_dump(Q,'Vsfx%i.pkl'%n_start) util.pickle_dump(S,'Vsfy%i.pkl'%n_start) print 'finished reconstruction' Q, S, primitive_vectors = sf.sf_filter(Q, S, primitive_vectors, filters=filters,save=save) print 'sorting peaks' return Q, S, primitive_vectors
def vac_msd(DV,DW,CV,CW,L): vacancies = np.zeros((DV.shape[0],1,3)) for k in range(len(DW)): print k #find the points that are nearest neighbor that are different index = np.where(DW[k] == 0)[0] if len(index) > 0: if len(index) > 1: index = index[1] vacancies[k][0] = CW[index] else: index = np.where(DV[k] == 0)[0] if len(index) > 1: index = index[1] vacancies[k][0] = CV[index] from MD.analysis.msd import msd_no_drift as msd #Find the msd of the system x, msd = msd(vacancies, L) msd = msd**0.5 util.pickle_dump([x,msd],'msd_vac.pkl') pyplot.plot(x,msd,xlabel='time',ylabel='msd',save='MSD_vacancey')
def msd_jump_average(VW,L): reload(diffuse) try: jump_d = util.pickle_load('jump_d.pkl') jump_t = util.pickle_load('jump_t.pkl') except: fid = open('large.xyz','r') M = readxyz.ReadCord(trajectory = 'large.xyz',frames = 777) crystal = M.cord_auto(['V','W']) bcc = np.zeros((777,432,1)) for frame in range(bcc.shape[0]): for i in range(bcc.shape[1]): if crystal[frame][i][0] > L[0]: bcc[frame][i]=0 else: bcc[frame][i]=1 jump_d, jump_t = diffuse.crystal_jump(VW,bcc,L) util.pickle_dump(jump_d,'jump_d.pkl') util.pickle_dump(jump_t,'jump_t.pkl') pyplot.plot(jump_t,jump_d,'','s',xlabel='time',ylabel='jump distance',save='msd_jump') hist_s,xs,max_hist=histogram(jump_d,bins=20) pyplot.plot(xs,hist_s,xlabel='distance',ylabel='count',save='jump_hist')
def distance_distribution(V,L,n_frames=15,n_start=1,end=10): #finds end to end distances and plots a histogram with that data 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 ######################################## #Plot Data for AA,AB,BB distances save_name='_time_'+'%i'%(n_start) start=n_start finish=n_start+n_frames max_hist=0 BB=hist(V[start:finish],V[start:finish],L,save_name,'B-B',end=end) pyplot.plot(BB[0][1:],BB[1][1:],xlabel='s',ylabel='g(s)',save='nnplot_'+save_name) out = open('dist%i.txt'%n_start,'w') out.write('\n') for i in range(len(BB[1])): out.write(('%.5f %.5f\n')%(BB[0][i],BB[1][i])) out.close()
def find_networks(M, VW, L,x,ndna=25): import MD.canalysis.connections as con import MD.analysis.connections as conn import MD.analysis.graph as graph #plot total number of connections connections = _connections(M) num_connections=conn.num_connections(connections,VW.shape[1]) con_all = [] for i in range(len(connections)): con_all.append(len(connections[i][0])) print len(x),len(num_connections) pyplot.plot(x,num_connections,xlabel='Time', ylabel='hyrbid. density', save='connections') pyplot.plot(x,con_all,xlabel='Time', ylabel='hyrbid', save='connections_all') plt.close() #get the info networks, num_networks, deg, neighbors, num_n, gr = graph.grapher(connections,VW.shape[1],ndna) util.pickle_dump(networks,'net.pkl') #plot the number of neighbors at each timesteps pyplot.plot(x,num_n,xlabel='Time', ylabel='num neighbors', save='neighbors') plt.close() print 'making plot' net = [] for i in networks: net.append(len(i)) pyplot.plot(x,net,xlabel='t',ylabel='networks',save='net') label = ['networks','1','2','3','4','5','6','7','8','9'] x = [x for i in range(len(deg))] #pyplot.plot(x,num_networks,xlabel='t',ylabel='Networks',save='net') #pyplot.plot_multi(x[:4],deg[:4],label,xlabel='time',ylabel='number',save='con_net') plt.close() return networks, num_networks, deg, neighbors, num_n, gr #pyplot.plot_multi(x[:4],deg[:4],label,xlabel='time',ylabel='number',save='con_net') plt.close() return networks, num_networks, deg, neighbors, num_n, gr
def vac_move_to(DV,DW): vacancies = np.zeros((DV.shape[0],1)) #find the vacancies in the simulations for k in range(len(DW)): #find the points that are nearest neighbor that are different index = np.where(DW[k] == 0)[0] if len(index) > 0: if len(index) > 1: index = index[1] vacancies[k] = index else: index = np.where(DV[k] == 0)[0] if len(index) > 1: index = index[1] vacancies[k] = index + DW.shape[1] #now that we have the indexes lets go back through and pick out where they #came from def check(vac, DW, DV): if vac > DW.shape[0]: return DV[vac-DW.shape[0]] else: return DW[vac] last = [] new = [] for k in range(1,vacancies.shape[0]): if vacancies[k] == vacancies[k-1]: last.append(0) new.append(0) else: last.append(check(vacancies[k][0],DW[k-1],DV[k-1])) new.append(check(vacancies[k-1][0],DW[k],DV[k])) count = 0 count_def = 0 print 'GNP that moved was' for i in last: if i == 1.0: count += 1 if i == -1.0: count_def += 1 out = open('count_def.txt','w') print 'not a defect' print count print 'a substitution' print count_def out.write('GNP that moved was\n') out.write(('not a defect %i\n')%(count)) out.write(('a substituion %i\n')%(count_def)) count = 0 count_def = 0 for i in new: if i == 1.0: count += 1 if i == -1.0: count_def += 1 print 'filled vacancy with' print 'not a defect' print count print 'a substitution' print count_def out.write('Filled vacancy with\n') out.write(('not a defect %i\n')%(count)) out.write(('a substituion %i\n')%(count_def)) count = 0 count_def = 0 print 'last vacancy filled with' for i in range(len(new)): if new[i] == 1.0: if new[i-1] == 0: count += 1 if new[i] == -1.0: if new[i-1] == 0: count_def += 1 print 'not a defect' print count print 'a substitution' print count_def out.write('last vacancy filled with\n') out.write(('not a defect %i\n')%(count)) out.write(('a substituion %i\n')%(count_def)) count = 0 count_def = 0 print 'First GNP that moved was' for i in range(len(last)): if last[i] == 1.0: if last[i-1] == 0: count += 1 if last[i] == -1.0: if last[i-1] == 0: count_def += 1 print 'not defect' print count print 'a substitution' print count_def out.write('First GNP moved was\n') out.write(('not a defect %i\n')%(count)) out.write(('a substituion %i\n')%(count_def)) x = range(len(new)) #Find the msd of the system pyplot.plot(x,new,xlabel='Time',ylabel='vac',save='vacancey_to') pyplot.plot(x,last,xlabel='Time',ylabel='vac',save='vacancey_from')
def find_defects(CV,CW,VW,V,W,L,n_finish=1,n_start=0,delta=20,filters=0.2): from MD.analysis.nearest_neighbor import ws_neighbors_point from MD.analysis.nearest_neighbor import close_neighbors_point ####### x = np.arange(n_start,n_finish,delta) lattice = [] for i in range(CV.shape[0]): lattice.append(int(points.dist(CV[0],CV[i],L)[0])) for i in range(CW.shape[0]): lattice.append(int(points.dist(CV[0],CW[i],L)[0])) points.unique(lattice) lattice.sort() print lattice rmin = lattice[1] / 2.0 rmax = lattice[2] / 2.0 +1 #for interstitial s = max(W.shape[1],V.shape[1]) #for vacancy #s = max(W.shape[1],V.shape[1]) DW = np.zeros((len(x),s)) DV = np.zeros((len(x),s)) vac_count = np.zeros((len(x),1)) int_count = np.zeros((len(x),1)) fid = open('defects.txt','w') master = [[],[]] for index,k in enumerate(x): print 'frame',k # Identify the points on the bcc Lattice which belong to A and B type #lets look at one point first # Assign each point to its place on the lattice #find the closest point ##################### N = [] N_V = [] N_W = [] #correct spot = 1 #vacancies = 0 #interstitials = 2 #substitions are negative for i in range(V.shape[1]): N = ws_neighbors_point(V[k],CV[i],L,i,rmin=rmin,rmax=rmax)[0] N_V.extend(N) num = len(N) if num == 0: N2 = ws_neighbors_point(W[k],CV[i],L,i,rmin=rmin,rmax=rmax)[0] N_W.extend(N2) num = -len(N2) DV[index][i] = num ########################### for i in range(V.shape[1]): N = ws_neighbors_point(W[k],CW[i],L,i+W.shape[1],rmin=rmin,rmax=rmax)[0] N_W.extend(N) num = len(N) if num == 0: N2 = ws_neighbors_point(V[k],CW[i],L,i+W.shape[1],rmin=rmin,rmax=rmax)[0] N_V.extend(N2) num = -len(N2) DW[index][i] = num #find the atoms that haven't been placed on the lattice yet IV = points.difference(range(V.shape[1]),N_V) IW = points.difference(range(W.shape[1]),N_W) print 'atoms not added list for debugging' print IV, IW for i in IV: #find closest lattice point nw, dw = close_neighbors_point(CW,V[k][i],L) nv, dv = close_neighbors_point(CV,V[k][i],L) if dw <= dv: #check to see if there is already an atom at that point print index print nw print DW.shape print CW.shape if DW[index][nw] == 1 or DW[index][nw] == -1: if DV[index][nv] == 0: DV[index][nv] = 1 N_V.extend([i]) else: DW[index][nw] = -2 N_V.extend([i]) if DW[index][nw] == 0: DW[index][nw] = -1 N_V.extend([i]) #check to see if there is already an atom at that point else: if DV[index][nv] == 1 or DV[index][nv] == -1: #if there isn't one at the other point add it if DW[index][nw] == 0: DW[index][nw] = -1 N_V.extend([i]) else: if DV[index][nv] == 1: DV[index][nv] = 2 if DV[index][nv] == -1: DV[index][nv] = -2 N_V.extend([i]) if DV[index][nv] == 0: DV[index][nv] = 1 N_V.extend([i]) for i in IW: nw, dw = close_neighbors_point(CW,W[k][i],L) nv, dv = close_neighbors_point(CV,W[k][i],L) if dv <= dw: if DV[index][nv] == 1 or DV[index][nv] == -1: if DW[index][nw] == 0: DW[index][nw] = 1 N_W.extend([i]) else: DV[index][nv] = -2 N_W.extend([i]) if DV[index][nv] == 0: DV[index][nv] = -1 N_W.extend([i]) else: if DW[index][nw] == 1 or DW[index][nw] == -1: if DV[index][nv] == 0: DV[index][nv] = -1 N_W.extend([i]) else: DW[index][nw] = 2 N_W.extend([i]) if DW[index][nw] == 0: DW[index][nw] = 1 N_W.extend([i]) #find the atoms that haven't been placed on the lattice yet IV = points.difference(range(V.shape[1]),N_V) IW = points.difference(range(W.shape[1]),N_W) ## print 'atoms not added list for debugging' print IV, IW print DW[index] print DV[index] print 'Defect list for lattice' #print out the vacency, substitutions def out_defect(A, index, fid, def_list, C=0): for i in range(A.shape[1]): if A[index][i] == 0: pr = 'vacecy at '+ str(i+C)+ '\n' try: def_list[0].extend(i+C) except: def_list[0].append(i+C) print pr fid.write(pr) if A[index][i] == -1: pr = 'substitution ' + str(i+C)+ '\n' print pr fid.write(pr) if A[index][i] == -2: pr = 'interstitial ' + str(i + C)+ '\n' try: def_list[1].extend(i+C) except: def_list[1].append(i+C) print pr fid.write(pr) if A[index][i] == 2: pr = 'interstitial ' + str(i + C)+ '\n' try: def_list[1].extend(i+C) except: def_list[1].append(i+C) print pr fid.write(pr) frame = 'Frame ' + str(k) + '\n' fid.write(frame) def_list = [[],[]] out_defect(DV, index, fid, def_list) out_defect(DW, index, fid, def_list, C = DV.shape[1]) if len(points.difference(def_list[0], master[0])) != 0: vac_count[index] += len(points.difference(def_list[1],master[1])) master[0] = def_list[0] if len(points.difference(def_list[1],master[1])) != 0: int_count[index] += len(points.difference(def_list[1],master[1])) master[1] = def_list[1] #find the atoms that haven't been placed on the lattice yet IV = points.difference(range(V.shape[1]),N_V) IW = points.difference(range(W.shape[1]),N_W) # Identify the defects surrounding each point #The total number of frames we are going to look at # Find the number of defects in each frame count = 0 substitutions = [] vacancies = [] intersticial = [] def count_def(A,check): count = 0 for i in A: if i == check: count +=1 return count def count_ldef(A,check): count = 0 for i in A: if i < check: count +=1 return count def count_adef(A,check): count = 0 for i in A: if abs(i) == check: count +=1 return count for k in range(DW.shape[0]): #find the points that are nearest neighbor that are different substitutions.append(count_ldef(DW[k],0)+count_ldef(DV[k],0)) vacancies.append(count_def(DW[k],0)+count_def(DV[k],0)) intersticial.append(count_adef(DW[k],2.0)+count_adef(DV[k],2.0)) print substitutions print vacancies print intersticial util.pickle_dump(DW,'DW.pkl') util.pickle_dump(DV,'DV.pkl') util.pickle_dump([substitutions, vacancies, intersticial, x],'plot_def.pkl') pyplot.plot3(x, substitutions, x, vacancies, x, intersticial, label1='substitutions',label2='vacancies',label3='intersticial', save='defects_per_frame',showleg=True) pyplot.plot(x, vac_count, save='defect_vac_diffusion_count') pyplot.plot(x, int_count, save='defect_int_diffusion_count') return DV, DW, [substitutions, vacancies, intersticial, x] return DV, DW
def int_msd(DV,DW,V,W,CV,CW,L): #we create an active_int which keeps track of the index at the current frame #we creat an all_int which keeps track of the intersticals #whenever the number of intersticials decerases we find the one that #vanished and add its trajectory to all_int #whenever teh number of intersticials increases we add a new trajectory #to the active ints interstitials = np.zeros((DV.shape[0],1,3)) last_index = 0 active_int = [] all_int = [] ########################## # Functions ######################## def find_nearest(point,CW,CV,L): current = 100 for i in CW: d = points.dist(point,i,L)[0] if d < current: current = d new_point = i for i in CV: d = points.dist(point,i,L)[0] if d < current: current = d new_point = i return new_point #place the intersticial into the active_int array def place_int(new_point, active_int,list_index,L): current = 100 for i in range(len(active_int)): if i not in list_index: d = points.dist(new_point,active_int[i][-1],L)[0] if d < current: current = d index = i try: index active_int[index].append(new_point) list_index.append(index) return index except: pass #find the distance between the new points and the active_int array def find_int_dist(new_point, active_int,L): current = 100 for i in range(len(active_int)): d = points.dist(new_point,active_int[i][-1],L)[0] if d < current: current = d return current def find_point(DV,CV,CW,i): if i < DV.shape[1]: new_point = CV[i] if i >= DV.shape[1]: new_point = CW[i-DV.shape[1]] return new_point ########################################### # Logic: Run through once ########################################### index = np.where(abs(DV[0]) == 2)[0] index = np.append(index, np.where(abs(DW[0]) == 2)[0] + DW.shape[1]) #xtrack keeps track of the frame when an interstitial is added x_track = [] for i in index: new_point = find_point(DV,CV,CW,i) active_int.append([new_point]) x_track.append(0) #find the point in the activt_interstitals and append it to the #the correct index last_index = index.shape[0] ########################################### #loop through the rest ########################################### for k in range(1,len(DW)): print k #find the points that are nearest neighbor that are different index = np.where(abs(DV[k]) == 2)[0] index = np.append(index, np.where(abs(DW[k]) == 2)[0] + DW.shape[1]) list_index = [] #sometimes there are more than one interstitial #we only want to make sure we follow the same one #so we look for the closest to that last position #if there is the same amount of intersticials if index.shape[0] == last_index: for i in index: new_point = find_point(DV,CV,CW,i) #find the point in the activt_interstitals and append it to the #the correct index place_int(new_point, active_int, list_index, L) #if an interstitical has been created if index.shape[0] > last_index: new_int = [] dist_int = [] for i in index: new_point = find_point(DV,CV,CW,i) #find the new interstitical dist_int.append(find_int_dist(new_point,active_int,L)) new_int.append(new_point) #find the index of the max point max_index = dist_int.index(max(dist_int)) for i in range(len(new_int)): if i != max_index: place_int(new_int[i], active_int,list_index, L) active_int.append([new_int[max_index]]) x_track.append(k) #if an intersticial has been destroyed if index.shape[0] < last_index: ann_int = [] dist_int = [] placed = [] for i in index: new_point = find_point(DV,CV,CW,i) #find the annihlated interstitical dist_int.append(find_int_dist(new_point,active_int,L)) ann_int.append(new_point) #find the index of the max point max_index = dist_int.index(max(dist_int)) for i in range(len(ann_int)): placed.append(place_int(ann_int[i],active_int,list_index,L)) #find the point to be removed dif = points.difference(range(len(active_int)),placed) #add the point to the list of all intersticials for i in dif: all_int.append(active_int[i]) #remove the point from the active list count = 0 for i in dif: del active_int[i-count] count+=1 last_index = index.shape[0] for i in active_int: all_int.append(i) print 'len int' print len(all_int) final_int = [] final_x = [] #lets filter out the short lived interstitials for i in range(len(all_int)): if len(all_int[i]) > 1: final_int.append(all_int[i]) final_x.append(x_track[i]) print len(final_int) print 'print x' print len(final_x) from MD.analysis.msd import msd_no_drift as msd #Find the msd of each interstitial msd_all = [] x_all = [] for i in final_int: A = np.zeros((len(i),1,3)) for j in range(len(i)): A[j][0][0] = i[j][0] A[j][0][1] = i[j][1] A[j][0][2] = i[j][2] x, msds = msd(A, L) msd_all.append(msds) x_all.append(x) #now we need to relate the msd to the point in time the interstital was #active msd_total = np.zeros(DV.shape[0]) for i,k in enumerate(final_x): print k for j in range(len(msd_all[i])): if k+j < msd_total.shape[0]: msd_total[k+j] += msd_all[i][j] #for i in range(1,msd_total.shape[0]): # msd_total[i] += msd_total[i-1] msd_total = msd_total**0.5 x = range(msd_total.shape[0]) util.pickle_dump([x,msd_total],'msd_int.pkl') pyplot.plot(x,msd_total,xlabel='time',ylabel='msd',save='MSD_int')