def connected_angles(VW,Z,L,connections, N_nodes, vertex_points=1, cut = 5): Cube = [[[] for j in range(N_nodes[0])] for l in range(len(connections))] for k,i in enumerate(connections): for j in i: #find the two connections #we need to + Adivide by the number of sites to get the right #major particle index A=j[0] B=j[1]+N_nodes[0] Cube[k][A].append(B) counter = np.zeros((len(Cube),4)) for k in range(len(Cube)): count_face = 0 count_all = 0 count_face_less = 0 count_all_less = 0 for i in range(len(Cube[k])): for j in points.unique(Cube[k][i]): if Cube[k][i].count(j)>=cut: count_all += 1 if angle.face_check(VW,Z,k,i,j,1,1,L): count_face += 1 else: count_all_less += 1 if angle.face_check(VW,Z,k,i,j,1,1,L): count_face_less += 1 counter[k] = [count_face,count_all,count_face_less,count_all_less] print 'finished counting' return counter
def sides_faces_mod(VW,Z,L,connections, N_nodes, vertex_points=1, cut = 5): A_points = vertex_points[0]*N_nodes[0] Cube = [[[] for j in range(sum(N_nodes))] for l in range(len(connections))] for k,i in enumerate(connections): for j in i: #find the two connections #we need to + Adivide by the number of sites to get the right #major particle index A=j[0] B=j[1]+N_nodes[0] #This provides the position of sides which are connected Cube[k][A].append(B) #add the connections to a list counter = np.zeros((len(Cube),3)) for k in range(len(Cube)): count_face = 0 count_all = 0 for j in range(len(Cube[k])): if len(Cube[k][j]) in cut: for N in points.unique(Cube[k][j]): count_all += 1 a = angle.face_check(VW,Z,k,j,N,L) if a+b==2: count_face += 1 if count_all == 0: counter[k] = [ 0,0,0] else: counter[k] = [count_face,count_all,count_face/float(count_all)] print 'finished counting' return counter
def nearpart_remove(): #print out directory fid = open('dna_2nuc.xyz','r') N_atoms = fid.readline() fid.readline() M = fid.readlines() V = [] count = 0 NP_center = [] #NP_center = index of center of particle #V = numpy array of all particle positions #index = "name of particle at each index' index = [] for line in M: index.append(line.split()[0]) V.append([float(line.split()[1]),float(line.split()[2]),float(line.split()[3])]) if line.split()[0] == 'V' or line.split()[0] == 'W': NP_center.append(count) count += 1 fid.close() V = np.array(V) Lx = 220 Ly = 110 Lz = 110 L = np.array([Lx, Ly, Lz]) print L #the center of the partilcl too_close = [] print NP_center C = NP_center[0] NP_size = NP_center[1] - NP_center[0] for i in NP_center: print i/NP_size for j in NP_center: if i != j: if points.dist(V[i],V[j],L)[0]<12: too_close.append([min(i,j),max(i,j)]) too_close = points.unique(too_close) remove = [] for i in too_close: remove.append(i[0]) #remove the NP which are too_close! #to do and write the new dna.xyz file print 'writing dna.xyz' out = open('dna_close_remove.xyz','w') out.write(('%i\n\n')%(V.shape[0])) count = 0 for i in range(V.shape[0]): if i in remove: i+=1 if count>=V.shape[0]-1: print 'breaking' break for j in range(NP_size): count = i * NP_size + j out.write(('%s %.2f %.2f %.2f\n')%(index[count],V[count][0],V[count][1],V[count][2]))
def search(connected,A,B): add=False for i in range(len(connected)): #is it in there already if connected[i].count(A)==1: if connected[i].count(B)==0: connected[i].append(B) if connected[i].count(B)==1: if connected[i].count(A)==0: connected[i].append(A) #look through connectd if there is an intersection, take the union and #delete what was there for i in range(len(connected)): for j in range(len(connected)): if intersection(connected[i],connected[j])!=[]: connected[i]=union(connected[i],connected[j]) connected[j]=connected[i] #Removed any doubles connected=unique(connected) return connected
def find_defects_mod(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 ####### debug = False 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 = min(W.shape[1],V.shape[1]) #for vacancy #s = max(W.shape[1],V.shape[1]) DW = np.zeros((len(x),CW.shape[0])) DV = np.zeros((len(x),CV.shape[0])) vac_count = np.zeros((len(x),1)) int_count = np.zeros((len(x),1)) fid = open('defects.txt','w') master = [[],[]] particle_frame = [] 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 = [] Vn = [] Wn = [] for i in V[k]: if abs(i[0]) < L[0]: Vn.append(i) for i in W[k]: if abs(i[0]) < L[0]: Wn.append(i) print 'Wn',len(Wn) print 'Vn',len(Vn) particle_frame.append(len(Wn)+len(Vn)) Wn = np.array(Wn) Vn = np.array(Vn) for i in range(CV.shape[0]): N = ws_neighbors_point(Vn,CV[i],L,i,rmin=rmin,rmax=rmax)[0] N_V.extend(N) num = len(N) if num == 0: N2 = ws_neighbors_point(Wn,CV[i],L,i,rmin=rmin,rmax=rmax)[0] N_W.extend(N2) num = -len(N2) DV[index][i] = num ########################### for i in range(CW.shape[0]): N = ws_neighbors_point(Wn,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(Vn,CW[i],L,i+V.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(Vn.shape[0]),N_V) IW = points.difference(range(Wn.shape[0]),N_W) ## if debug: print 'atoms not added listed after first sorting' print IV, IW print DW[index] print DV[index] for i in IV: #find closest lattice point nw, dw = close_neighbors_point(CW,Vn[i],L) nv, dv = close_neighbors_point(CV,Vn[i],L) if dw <= dv: #check to see if there is already an atom at that point 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,Wn[i],L) nv, dv = close_neighbors_point(CV,Wn[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(Vn.shape[0]),N_V) IW = points.difference(range(Wn.shape[0]),N_W) ## if debug: 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) if debug: print pr fid.write(pr) if A[index][i] == -1: pr = 'substitution ' + str(i+C)+ '\n' if debug: 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) if debug: 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) if debug: 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 'substitions' print substitutions print 'vacancies' print vacancies print 'interstitials' print intersticial util.pickle_dump(DV,'DV_s.pkl') util.pickle_dump(DW,'DW_s.pkl') util.pickle_dump([substitutions, vacancies, intersticial, x],'plot_def_s.pkl') pyplot.plot3(x, substitutions, x, particle_frame, x, intersticial, label1='substitutions',label2='number of particles',label3='intersticial', save='defects_per_frame_surface',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]