def polymer_end_2_end(M, L, frames ): hpy = h5py.File('polymer_stetching.hdf5','w') delta = 1 P = M.cord_frames(['M'],frames) V = M.cord_frames(['V'],frames) polymers = P.shape[1]/(2*V.shape[1]) for count, k in enumerate(frames): counter = 0 ps2pe = np.zeros(V.shape[1]*polymers) c2pe = np.zeros(V.shape[1]*polymers) c2ps = np.zeros(V.shape[1]*polymers) for i in range(V.shape[1]): for j in range(0,2*polymers,2): ps2pe[counter] = points.dist(P[count][i*(2*polymers)+j],P[count][i*(2*polymers)+j+1],L[k])[0] c2ps[counter] = points.dist(V[count][i],P[count][i*(2*polymers)+j],L[k])[0] c2pe[counter] = points.dist(V[count][i],P[count][i*(2*polymers)+j+1],L[k])[0] counter+=1 dset = hpy.create_dataset("%ips2pe"%k, data = ps2pe) dset.attrs.create("N_atoms",V.shape[1]*polymers) dset.attrs.create("L",L[k][0]) dset.attrs.create("n_frames",delta) dset = hpy.create_dataset("%ic2ps"%k, data = c2ps) dset.attrs.create("N_atoms",V.shape[1]*polymers) dset.attrs.create("L",L[k][0]) dset.attrs.create("n_frames",delta) dset = hpy.create_dataset("%ic2pe"%k, data = c2pe) dset.attrs.create("N_atoms",V.shape[1]*polymers) dset.attrs.create("L",L[k][0]) dset.attrs.create("n_frames",delta) hpy.close()
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]
def find_neighbors(M,point,L,rcut=17): neighbors = [] for i in range(len(M)): if points.dist(M[i],point,L)[0]>1: if points.dist(M[i],point,L)[0]<rcut: neighbors.append(M[i]) return neighbors
def close_neighbors_point(M,point,L): neighbors = False lowest = 100 for i in range(M.shape[0]): if dist(M[i],point,L)[0] != 0: D = dist(M[i],point,L)[0] if lowest > D: lowest = D neighbor = i return neighbor, lowest
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
def find_neighbors(index, CW, CV, L, cut = 17): point = find_lattice(index,CW,CV) V_neighbors = [] W_neighbors = [] for i,j in enumerate(CV): if points.dist(j,point,L)[0] < cut: if points.dist(j,point,L)[0] > 1: V_neighbors.append(i) for i,j in enumerate(CW): if points.dist(j,point,L)[0] < cut: if points.dist(j,point,L)[0] > 1: W_neighbors.append(i) return V_neighbors, W_neighbors
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 close_2neighbors_point(M,point,L): neighbors = [] vectors = [] lowest = 100 neighbor2 = 0 for i in range(M.shape[0]): if dist(M[i],point,L)[0] != 0: D = dist(M[i],point,L)[0] if lowest > D: lowest = D neighbor = i neighbor2 = neighbor try: return neighbor, neighbor2, lowest except: print "error No neighbors were found try increasing"
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 draw_polymer(M,L, frames,NP=[1,2], rcut=1.0, step=5e4): print "getting cors" P = M.cord_frames(['M'],frames) VW = M.cord_frames(['V','W'],frames) print "finished getting cords" ndna = P.shape[1]/VW.shape[1] #distance from center to edge of cube #draw edges of the cube def write_line(fid,p1,p2): s1 = "{%.2f %.2f %.2f}"%(p1[0],p1[1],p1[2]) s2 = "{%.2f %.2f %.2f}"%(p2[0],p2[1],p2[2]) fid.write(("draw arrow %s %s\n")%(s1,s2)) c = ['green','blue','red'] for count,k in enumerate(frames): fid = open('polymer%i.tcl'%k,'w') fid.write('proc vmd_draw_arrow {mol start end} {\n' + 'set middle [vecadd $start [vecscale 0.9 [vecsub $end'+ ' $start]]]\n'+'graphics $mol cylinder $start $middle' + ' radius 0.15\n'+'graphics $mol cone $middle $end radius' + ' 0.25\n}\n') #for i in range(VW.shape[1]): for cc,i in enumerate(NP): color = c[cc] fid.write('draw color '+color+'\n') for j in range(0,ndna,2): d = points.dist(P[count][j+i*ndna],P[count][j+1+i*ndna],L[k])[1] write_line(fid,P[count][j+i*ndna],P[count][j+i*ndna]+d) fid.close()
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 connections(A,B,L,rcut=1.5): counter=[] for k in range(A.shape[0]): count = [] print 'step',k for i in range(A.shape[1]): for j in range(B.shape[1]): d = dist(A[k][i],B[k][j],L)[0] if d<rcut: count.append([i,j+A.shape[1]]) counter.append(count) return counter
def connections_min_max(A,B,L,rcut=1.5,rmin=1): counter=[] for k in range(A.shape[0]): count = [] print 'step',k for i in range(A.shape[1]): for j in range(B.shape[1]): d = dist(A[k][i],B[k][j],L)[0] if (d<rcut) & (d>rmin): count.append([i,j+A.shape[1]]) counter.append(count) return counter
def add_particles(self,M): self.particle_list = np.zeros((M.shape[0])) for i in range(M.shape[0]): dsmall = 100 index = 0 for j in range(len(self.box)): d = points.dist(M[i],self.box[j][0],self.L)[0] if d < dsmall: index = j dsmall = d self.box[index][2].append(i) self.particle_list[i] = int(index)
def min_distance(A1,A2,L): num=0 side1=0 side2=0 smallest=50 for i in range(A1.shape[0]): for j in range(A2.shape[0]): num = dist(A1[i],A2[j],L)[0] if smallest > num: smallest = num side1 = i side2 = j return side1,side2
def end_end(V,W,M,L): T=M.cord_auto(['T']) K=M.cord_auto(['K']) V=M.cord_auto(['V']) W=M.cord_auto(['W']) ndna = T.shape[1]/V.shape[1] #K-V #W-T VK=[] WT=[] last = V.shape[0] #find center-ssdna particle distance for k in range(last-5,last): for i in range(V.shape[1]): for j in range(ndna): VK.append(points.dist(V[k][i],K[k][j+i*ndna],L)[0]-3) WT.append(points.dist(W[k][i],T[k][j+i*ndna],L)[0]-3) hist_K,xK,max_k=histogram(VK,10) hist_T,xT,max_T=histogram(WT,10) plt.close() pyplot.plot_bar(xK,hist_K,save='VK_distance') plt.close() pyplot.plot_bar(xT,hist_T,save='WT_distance') plt.close() #find the length of the polymer KT=M.cord_auto(['K','T']) S=M.cord_auto(['M']) edge=[] for k in range(last-5,last): for i in range(S.shape[1]): edge.append(points.dist(KT[k][i],S[k][i],L)[0]) hist_edge,xedge,max_edge=histogram(edge,50) pyplot.plot_bar(xedge,hist_edge,save='polymer_length') plt.close()
def __init__(self,L,delta=4): #initialize the box delta = L[0]/round(delta) self.box = [] self.L = L for i in np.arange(-L[0]/2.,L[0]/2.,delta): for j in np.arange(-L[1]/2.,L[1]/2.,delta): for k in np.arange(-L[2]/2.,L[2]/2.,delta): self.box.append([np.array([i,j,k]),[],[]]) #add the box neighbors for i in range(len(self.box)): for j in range(len(self.box)): if points.dist(self.box[i][0],self.box[j][0],L)[0] <= 3**0.5*delta: self.box[i][1].append(j)
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
def msd_r(A,lattice,L): #First find the closest to the real coordinate msd=np.zeros((A.shape[0],2)) msd+=L[0]+10 for i in range(A.shape[0]): for j in range(lattice.shape[0]): D=points.dist(A[i],lattice[j],L)[0] #if the distance is shorter store the point and the distance if abs(msd[i][1])>abs(D): msd[i][0]=j msd[i][1]=D #find the total msd MSD=0 for i in range(msd.shape[0]): MSD+=msd[i][1]**2 MSD_total= MSD/A.shape[0] print 'msd for choice',MSD_total return MSD_total
def diff(A,L,step=50000*5): #find the drift print A.shape Drift = drift_position(A,L)[0] #find msd num = A[0].shape[0] print num print num frames=A.shape[0] print "Calculating MSD" MSD=np.zeros((frames-1)) r_sum = 0 for k in range(0,frames-1): for i in range(num): d = points.dist(A[0][i][0:3], A[k][i][0:3], L) r_sum = abs(d[0]) + r_sum MSD[k] = r_sum x = np.arange(0, A.shape[0] * step - step, step) return x,MSD
def drift_position(A,L): num = A[0].shape[0] print "Calculating drift of position" D = np.zeros(((A.shape[0]-1),3)) Dsum = np.zeros(((A.shape[0]-1),1)) x_whole = 0; y_whole = 0; z_whole = 0 for k in range(A.shape[0] - 1): x_sum = 0; y_sum = 0; z_sum = 0 for i in range(num): d, dx = points.dist(A[k][i], A[k+1][i], L) x_sum += dx[0] y_sum += dx[1] z_sum += dx[2] D[k][0] = (x_sum / num + x_whole) D[k][1] = (y_sum / num + y_whole) D[k][2] = (z_sum / num + z_whole) Dsum[k] = (((x_sum / num +x_whole)**2 +(y_sum / num + y_whole)**2 +(z_sum / num + z_whole)**2)**0.5) x_whole = x_sum / num + x_whole y_whole = y_sum / num + y_whole z_whole = z_sum / num + z_whole return D, Dsum
positions.append([x,y,z]) fid.close() #Transform L = np.array([50,50,50]) w = np.array([[1,0,0],[0,1,0],[0,0,1]]) V = np.array([0,0,0]) x_r = points.unit(np.array(orientations[1])) y_r = points.unit(np.array(orientations[2])) z_r = points.unit(np.array(orientations[3])) v = np.array([x_r,y_r,z_r]) print points R = points.reference_rotation(w,v) location = [] for i in range(len(P)): d = points.dist(V,P[i],L)[0] c_r = points.unit(points.vector1d(V,P[i],L)) location.append(points.unit(np.dot(R,np.transpose(c_r)))*d) #write out positions.extend([0,0,0]) fid.open('cube_unit_cell.xyz','w') fid.write('%i \n\n'%(len(positions)*len(location))) for i in range(len(positions)): for j in range(len(location)): x = location[j][0] + positions[i][0] y = location[j][1] + positions[i][1] z = location[j][2] + positions[i][2] fid.write('Z %.2f %.2f %.2f\n'%(x,y,z))
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]
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')
def ssDNA_gauss(M,VW, Z,L, frames, rcut=1.0, step=5e4): try: #V = util.pickle_load('V.pkl') P = util.pickle_load('SSDNA.pkl') except: P = M.cord_auto(['K','T']) util.pickle_dump(P,'SSDNA.pkl') gauss_map = [] w = np.array([[1,0,0],[0,1,0],[0,0,1]]) ndna = P.shape[1]/VW.shape[1] print P.shape for k in frames: location = [] print k try: for i in range(VW.shape[1]): #we must rotate about a specific cube reference frame if i in range(20): V = VW[k][i] x_r = points.unit(points.vector1d(V,Z[k][i*6+1],L[k])) y_r = points.unit(points.vector1d(V,Z[k][i*6+2],L[k])) z_r = points.unit(points.vector1d(V,Z[k][i*6+5],L[k])) dd = points.dist(V,Z[k][i*6+5],L[k])[0] v = np.array([x_r,y_r,z_r]) R = points.reference_rotation(v,w) for j in range(ndna): d = points.dist(V,P[k][j+i*ndna],L[k])[0] c_r = points.unit(points.vector1d(V,P[k][j+i*ndna],L[k])) location.append(points.unit(np.dot(R,np.transpose(c_r)))*d) except: print 'something went wrong here' gauss_map.append(location) ######### fid = open('gaussmap_dna.xyz','w') max_gauss = 0 for k in gauss_map: if len(k) > max_gauss: max_gauss = len(k) for k in range(len(gauss_map)): fid.write('%i\n%i\n'%(max_gauss+4,frames[k])) fid.write('E %.2f 0 0\n'%dd) fid.write('E 0 %.2f 0\n'%dd) fid.write('E 0 0 %.2f\n'%dd) fid.write('V 0 0 0\n') for i in gauss_map[k]: fid.write('N %.3f %.3f %.3f\n'%(i[0],i[1],i[2])) for i in range(max_gauss - len(gauss_map[k])): fid.write('N 0 0 0\n') fid.close() ########### fid = open('gaussmap_dna_step.xyz','w') max_gauss = 0 step = 10 for k in gauss_map: if len(k) > max_gauss: max_gauss = len(k) max_gauss = max_gauss*step for s in range(0,len(gauss_map)-step,step): fid.write('%i\n\n'%(max_gauss+4)) fid.write('E 1 0 0\n') fid.write('E 0 1 0\n') fid.write('E 0 0 1\n') fid.write('V 0 0 0\n') count = 4 for k in range(s,s+step): for i in gauss_map[k]: fid.write('N %.3f %.3f %.3f\n'%(i[0],i[1],i[2])) count+=1 for i in range(max_gauss+4 - count): fid.write('N 0 0 0\n') fid.close()
def polymer_gauss(M,VW, Z,L, frames, rcut=1.0, step=5e4): #\brief find the gauss map of polymers surrounding NC try: #V = util.pickle_load('V.pkl') P = util.pickle_load('M.pkl') except: P = M.cord_auto(['M']) util.pickle_dump(P,'M.pkl') A = VW.shape[1]/2 gauss_map = [] w = np.array([[1,0,0],[0,1,0],[0,0,1]]) ndna = P.shape[1]/VW.shape[1] print P.shape for k in frames: location = [] print k try: for i in range(VW.shape[1]): #we must rotate about a specific cube reference frame if i in range(1): V = VW[k][i] x_r = points.unit(points.vector1d(V,Z[k][i*6+1],L[k])) y_r = points.unit(points.vector1d(V,Z[k][i*6+2],L[k])) z_r = points.unit(points.vector1d(V,Z[k][i*6+5],L[k])) v = np.array([x_r,y_r,z_r]) R = points.reference_rotation(v,w) for j in range(1,ndna,2): d = points.dist(V,P[k][j+i*ndna],L[k])[0] c_r = points.unit(points.vector1d(V,P[k][j+i*ndna],L[k])) location.append(points.unit(np.dot(R,np.transpose(c_r)))*d) except: print 'something went wrong here' gauss_map.append(location) ######### #fid = open('gaussmap_polymer.xyz','w') #max_gauss = 0 #for k in gauss_map: # if len(k) > max_gauss: # max_gauss = len(k) #for k in range(len(gauss_map)): # fid.write('%i\n%i\n'%(max_gauss+4,frames[k])) # fid.write('E 1 0 0\n') # fid.write('E 0 1 0\n') # fid.write('E 0 0 1\n') # fid.write('V 0 0 0\n') # for i in gauss_map[k]: # fid.write('N %.3f %.3f %.3f\n'%(i[0],i[1],i[2])) # for i in range(max_gauss - len(gauss_map[k])): # fid.write('N 0 0 0\n') #fid.close() ########### fid = open('gaussmap_polymers_total.xyz','w') max_gauss = 0 for k in gauss_map: if len(k) > max_gauss: max_gauss = len(k) max_gauss = max_gauss*len(gauss_map) fid.write('%i\n\n'%(max_gauss+4)) fid.write('E 1 0 0\n') fid.write('E 0 1 0\n') fid.write('E 0 0 1\n') fid.write('V 0 0 0\n') count = 4 for k in range(len(gauss_map)): for i in gauss_map[k]: fid.write('N %.3f %.3f %.3f\n'%(i[0],i[1],i[2])) count+=1 fid.close()