def rotation_angle(M,Z,L,index=0): theta = [] v1 = [] sides = Z.shape[1]/M.shape[1] for i in range(M.shape[0]): v1.append(points.vector1d(M[i][index],Z[i][index*sides],L[i])) for i in range(M.shape[0]-1): theta.append(points.angle_between(v1[i],v1[i+1])) return theta
def diffusion(M,Z,L,index=0,t0=0,tfinal=1): theta = [] v1 = [] sides = Z.shape[1]/M.shape[1] for i in range(t0,tfinal): v1.append(points.unit(points.vector1d(M[i][index],Z[i][index*sides],L[i]))) for i in range(tfinal-t0): theta.append(np.dot(v1[0],v1[i])) return theta
def single_rotation_box(M,Z,L,index=0): theta = [] phi = [] sides = Z.shape[1]/M.shape[1] v = np.zeros((M.shape[0],3)) for k in range(M.shape[0]): v[k] = points.vector1d(M[k][index],Z[k][index*sides],L[k]) spher = xyz_to_spherical(v) theta = spher[:,1] phi = spher[:,2] return theta, phi
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 cube_vectors(V,E,L): vec = [] for i in E: vec.append(points.unit(points.vector1d(V,i,L))) return vec
def old_cubatic_order(M,Z,L,select=0): #Choose references cube ref = M[0][select] us = points.unit(points.vector1d(ref,Z[0][select*6],L)) ws = points.unit(points.vector1d(ref,Z[0][select*6+1],L)) vs = points.unit(points.vector1d(ref,Z[0][select*6+4],L)) #################################################### #Create u,w,v based on best alignment with reference cube u = [] v = [] w = [] for k in range(M.shape[0]): for i in range(M.shape[1]): if i != select: vc = cube_vectors(M[k][i],Z[k][i*6:i*6+6],L) usmall = 0 vsmall = 0 wsmall = 0 for j in range(1,len(vc)): if points.angle_between(us,vc[j])<=points.angle_between(us,vc[usmall]): usmall = j if points.angle_between(ws,vc[j])<=points.angle_between(ws,vc[wsmall]): wsmall = j if points.angle_between(vs,vc[j])<=points.angle_between(vs,vc[vsmall]): vsmall = j u.append(vc[usmall]) v.append(vc[vsmall]) w.append(vc[wsmall]) else: u.append(ws) v.append(us) w.append(vs) #Find Ordering Tesnors Quu = np.zeros((3,3)) Qww = np.zeros((3,3)) Qvv = np.zeros((3,3)) for N in range(len(u)): for i in range(3): for j in range(3): Quu[i,j] += 3. * u[N][i]*u[N][j] - delta(i,j) Qvv[i,j] += 3. * v[N][i]*v[N][j] - delta(i,j) Qww[i,j] += 3. * w[N][i]*w[N][j] - delta(i,j) Quu = Quu / (2.*len(u)) Qvv = Qvv / (2.*len(v)) Qww = Qww / (2.*len(w)) #Find eigenvalues e_w = np.linalg.eig(Qww) e_u = np.linalg.eig(Quu) e_v = np.linalg.eig(Qvv) #Identify Laboratory Z,Y and X axis #print e_w,'\n',e_u,'\n',e_v def find_max(e): evalue = e[0][0] index = 0 if e[0][1] > evalue: evalue = e[0][1] index = 1 if e[0][2] > evalue: evalue = e[0][2] index = 2 return evalue, index #get index of eigenvector and evalue e_plus_v = find_max(e_v) e_plus_u = find_max(e_u) e_plus_w = find_max(e_w) #find Z s = [] if e_plus_v[0] == max(e_plus_v[0],e_plus_u[0],e_plus_w[0]): z = e_v[1][e_plus_v[1]] Qz = Qvv s.append(0) if e_plus_v[0] == min(e_plus_v[0],e_plus_u[0],e_plus_w[0]): x = e_v[1][e_plus_v[1]] Qx = Qvv s.append(0) if e_plus_u[0] == max(e_plus_v[0],e_plus_u[0],e_plus_w[0]): z = e_u[1][e_plus_u[1]] Qz = Quu s.append(1) if e_plus_u[0] == min(e_plus_v[0],e_plus_u[0],e_plus_w[0]): x = e_u[1][e_plus_u[1]] Qx = Quu s.append(1) if e_plus_w[0] == max(e_plus_v[0],e_plus_u[0],e_plus_w[0]): z = e_w[1][e_plus_w[1]] Qz = Qww s.append(2) if e_plus_w[0] == min(e_plus_v[0],e_plus_u[0],e_plus_w[0]): x = e_w[1][e_plus_w[1]] Qx = Qww s.append(2) if len(s) != 2: print 'error too Qx and Qz were not selected properly' asdfasdf if 0 not in s: y = e_v[1][e_plus_v[1]] Qy = Qvv s.append(0) if 1 not in s: y = e_u[1][e_plus_u[1]] Qy = Quu s.append(1) if 2 not in s: y = e_w[1][e_plus_w[1]] Qy = Qww s.append(2) x = np.cross(z,y) #print 'angles between Laboratory' print points.angle_between(z,y) #Find Q22 and Q00 Q00 = np.dot(np.dot(z,Qz),z) #Q00 = (np.dot(np.dot(z,Qz),z)+np.dot(np.dot(y,Qy),y)+np.dot(np.dot(x,Qx),x))/3. Q22 = (np.dot(np.dot(x,Qx),x) + np.dot(np.dot(y,Qy),y) - np.dot(np.dot(x,Qy),x) - np.dot(np.dot(y,Qx),y))/3. return Q00, Q22
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()