def findsymmetry(vs,ts,xyzpnts): tfname="tmpsym.in" tf=open(tfname,"w") wrdata="Comment line\n" wrdata+="0\taccuracy\n" wrdata+="1\tlattice form: vectors\n" wrdata+="%g %g %g\n"%(vs[0][0],vs[0][1],vs[0][2]) wrdata+="%g %g %g\n"%(vs[1][0],vs[1][1],vs[1][2]) wrdata+="%g %g %g\n"%(vs[2][0],vs[2][1],vs[2][2]) wrdata+="1\n" wrdata+="1 0 0\n0 1 0\n0 0 1\n" wrdata+="%d\n"%(sum(ts)) types=" ".join([str(k) for k in flatten([[i+1 for j in range(ts[i])] for i in range(len(ts))])]) wrdata+="%s\n"%types for i,dat in enumerate(xyzpnts): wrdata+="%g %g %g\n"%(dat[0],dat[1],dat[2]) tf.write(wrdata) tf.close() #Issue the findsym command and parse the data os.system("findsym < %s > temp"%tfname) os.system("rm %s"%tfname) utpt=open("temp","r").readlines() os.system("rm temp") for line in utpt: if "space_group_name" in line: print "Symmetry Space Group= "+" ".join(line.split()[1:]) break
def cellNeighbs(celli): #Uses Ncell and Ncells, these must be defined correctly as #the total number of cells and cell dimensions respectively. coordx=int(floor(celli/(Ncy*Ncz))) #Cell coordinates coordy=int(floor(celli%(Ncy*Ncz)/Ncz)) coordz=int(celli%Ncz) cxs=[(coordx-1)%Ncx, coordx, (coordx+1)%Ncx ] #Neighbor coordinates cys=[(coordy-1)%Ncy, coordy, (coordy+1)%Ncy ] czs=[(coordz-1)%Ncz, coordz, (coordz+1)%Ncz ] cneighbs= [[[(cx,cy,cz) for cz in czs] for cy in cys] for cx in cxs] cneighbs= flatten(flatten(cneighbs)) cneighbs= set([coord2ind(cn) for i,cn in enumerate(cneighbs)]) return cneighbs
def findsymmetry(vs, ts, xyzpnts): tfname = "tmpsym.in" tf = open(tfname, "w") wrdata = "Comment line\n" wrdata += "0\taccuracy\n" wrdata += "1\tlattice form: vectors\n" wrdata += "%g %g %g\n" % (vs[0][0], vs[0][1], vs[0][2]) wrdata += "%g %g %g\n" % (vs[1][0], vs[1][1], vs[1][2]) wrdata += "%g %g %g\n" % (vs[2][0], vs[2][1], vs[2][2]) wrdata += "1\n" wrdata += "1 0 0\n0 1 0\n0 0 1\n" wrdata += "%d\n" % (sum(ts)) types = " ".join([ str(k) for k in flatten([[i + 1 for j in range(ts[i])] for i in range(len(ts))]) ]) wrdata += "%s\n" % types for i, dat in enumerate(xyzpnts): wrdata += "%g %g %g\n" % (dat[0], dat[1], dat[2]) tf.write(wrdata) tf.close() #Issue the findsym command and parse the data os.system("findsym < %s > temp" % tfname) os.system("rm %s" % tfname) utpt = open("temp", "r").readlines() os.system("rm temp") for line in utpt: if "space_group_name" in line: print "Symmetry Space Group= " + " ".join(line.split()[1:]) break
def cellNeighbs(celli): #Uses Ncell and Ncells, these must be defined correctly as #the total number of cells and cell dimensions respectively. coordx = int(floor(celli / (Ncy * Ncz))) #Cell coordinates coordy = int(floor(celli % (Ncy * Ncz) / Ncz)) coordz = int(celli % Ncz) cxs = [(coordx - 1) % Ncx, coordx, (coordx + 1) % Ncx] #Neighbor coordinates cys = [(coordy - 1) % Ncy, coordy, (coordy + 1) % Ncy] czs = [(coordz - 1) % Ncz, coordz, (coordz + 1) % Ncz] cneighbs = [[[(cx, cy, cz) for cz in czs] for cy in cys] for cx in cxs] cneighbs = flatten(flatten(cneighbs)) cneighbs = set([coord2ind(cn) for i, cn in enumerate(cneighbs)]) return cneighbs
def secondShell(neighbs): shell2 = list() #loop over each central atoms for i, ineighbs in enumerate(neighbs): #use set to get uniques ashell = list(set(flatten([neighbs[j] for j in ineighbs] + ineighbs))) shell2.append(ashell) return shell2
def secondShell(neighbs): shell2=list() #loop over each central atoms for i,ineighbs in enumerate(neighbs): #use set to get uniques ashell = list(set(flatten([neighbs[j] for j in ineighbs]+ineighbs))) shell2.append(ashell) return shell2
def secondShell(neighbs): shell2 = list() # loop over each central atoms for i, ineighbs in enumerate(neighbs): # use set to get uniques ashell = list(set([z for z in flatten([neighbs[j] for j in ineighbs])] + ineighbs)) try: ashell.remove(i) # remove central atom from neighbor list (atom can't be a neighbor to itself) except ValueError: pass shell2.append(ashell) return shell2
def rdf_by_adf(atoms,neighbs,basis,rcut=10.0,nADFbins=45,nRDFbins=100,angtype='deg'): #atoms: list of atoms[N][3] #neighbs: the *full* neighbor list for atoms #angtype: 'deg' or 'rad' #nbins: number of bins to store in radial distro #The angular range is always 0-180 deg and angles are taken modulo 180 #This function bins bond length by the angles to which they belong. bins = zeros(nADFbins*nRDFbins) natoms=len(atoms) atoms.shape=natoms*3 nneighbsf=array([len(i) for i in neighbs]) neighbsf=array([i for i in flatten(neighbs)]) cut=rcut b=basis b.shape=9 weave.inline(RDFBYADFcode,['atoms','natoms','neighbsf','nneighbsf','bins','nADFbins','nRDFbins','cut','b']) atoms.shape=[len(atoms)/3,3] adfVals = [(i+0.5)*180./nADFbins for i in range(nADFbins)] rdfVals = [(i+0.5)*rcut/nRDFbins for i in range(nRDFbins)] bins.shape=[nADFbins,nRDFbins] dr=float(rcut)/nRDFbins #Ndensity=N/volume(basis) for i,r in enumerate(rdfVals): m = sum(bins[:,i]) if i==0: vol=4.0*pi*dr*dr*dr/3.0 else: vol=4.0*pi*r*r*dr for j in range(nADFbins): if m==0: m=1 bins[j,i]/=vol return [(adfVals,rdfVals),bins]
def adf(atoms,neighbs,basis,cutoff,nbins=360,angtype='deg'): #atoms: list of atoms[N][3] #neighbs: the *full* neighbor list for atoms #angtype: 'deg' or 'rad' #nbins: number of bins to store in radial distro #The angular range is always 0-180 deg and angles are taken modulo 180 bins = zeros(nbins) cut=cutoff natoms=len(atoms) atoms.shape=natoms*3 b=basis b.shape=9 nneighbsf=array([len(i) for i in neighbs]) neighbsf=array([i for i in flatten(neighbs)]) weave.inline(ADFcode,['atoms','natoms','neighbsf','nneighbsf','bins','nbins','b','cut'],compiler=('gcc')) b.shape=[3,3] atoms.shape=[len(atoms)/3,3] abins = [(i+0.5)*180./nbins for i in range(nbins)] bins /= nbins return [abins,bins]
exit(0) if path.isdir(sys.argv[1]): outcar = open(sys.argv[1] + "/OUTCAR", "r") poscar = open(sys.argv[1] + "/POSCAR", "r") #need to use the poscar to fetch the atom types elif path.isfile(sys.argv[1]): outcar = False poscar = open(sys.argv[1], "r") [basis, atypes, atoms, head, poscar] = poscarIO.read(poscar.readlines()) [v1, v2, v3] = basis atoms = zip(*atoms) ax, ay, az = atoms[0], atoms[1], atoms[2] afx, afy, afz = [0] * len(ax), [0] * len(ay), [0] * len(az) types = [i for i in flatten([[i] * num for i, num in enumerate(atypes)])] startconfig = 0 plotdisabled = False if outcar: if (len(sys.argv) >= 3): startconfig = int(sys.argv[2]) if (len(sys.argv) >= 4): if int(sys.argv[3]) == 0: plotdisabled = True if not (plotdisabled): from mayavi import mlab global thelock thelock = threading.Event()
def usage(): print "Usage:" print "%s <POSCAR> <XDATCAR> <optional: starting config #> <optional 0: disables plotting>"%(sys.argv[0].split("/")[-1]) #Reading in the options and preparing for file reading if len(sys.argv)<3: usage() exit(0) poscar = open(sys.argv[1],"r") xdatcar = open(sys.argv[2],"r").readlines()[6:] v1,v2,v3,atypes,ax,ay,az,head,poscar=readposcar(poscar.readlines()) afx,afy,afz=[0]*len(ax),[0]*len(ay),[0]*len(az) types=[i for i in flatten([[i]*num for i,num in enumerate(atypes)])] startconfig=0 plotdisabled=False if (len(sys.argv)>=4): startconfig=int(sys.argv[3]) if (len(sys.argv)>=5): if int(sys.argv[4])==0: plotdisabled=True if not(plotdisabled): from mayavi import mlab global thelock thelock=threading.Event() count=0
lval="" xylabels={"BO" :[r"BondOrder($Q_%s$)"%str(lval), r"$P(Q_%s)$"%str(lval)], "CN" :[r"Coordination Number", r"P(CN)"], "RDF":[r"R$(\AA)$", "#_Bonds"], "ADF":[r"$\theta(deg)$", "#_Bond_Angles"], "BA" :[r"R$(\AA)$", r"$G_{%s}(r)$"%str(lval)], "SF" :[r"Q$(\AA^{-1})$", r"S(Q)"]} if args.averageFlag: if op not in ["BO","CN","TN","TET"]: t = zip(*[orderVals[i][1] for i in range(len(orderVals))]) avgy = map(lambda x:sum(x)/len(x),t) avgx = orderVals[0][0] elif op=="CN": hd,rcuts=zip(*orderVals) hd = [i for i in flatten(list(hd))] #flatten for averaging avgy,avgx,dummy=pl.hist(hd,bins=range(0,16),visible=False,normed=True) avgx = avgx[:-1] pl.xlabel(xylabels["CN"][0]) pl.ylabel(xylabels["CN"][1]) if args.saveFlag: if op in ["TN","TET"]: savetxt("AVERAGE."+op+str(lval),array([avgx,avgy]).T,delimiter=" ") elif op in ["ADF"]: savetxt("AVERAGE."+op+str(args.rcut),array([avgx,avgy]).T,delimiter=" ",header=" ".join(xylabels[op]),comments="") else: savetxt("AVERAGE."+op+str(lval),array([avgx,avgy]).T,delimiter=" ",header=" ".join(xylabels[op]),comments="") exit(0) else:
rcut=3.1 #Get the order parameter and convert to integer format (opsn) for coloring of atoms if opFlag: ops,rcut = orderParams[op](np.array(atoms),np.array(basis),l=lval,rcut=rcut) elif ops==None: ops = types if shell2Flag: bounds = [[0,basis[0][0]],[0,basis[1][1]],[0,basis[2][2]]] neighbs = neighbors(atoms,bounds,rcut) secondShell = list() for a,firstNeighbs in enumerate(neighbs): secondNeighbs = [neighbs[i] for i in firstNeighbs] totalNeighb = set(datatools.flatten([firstNeighbs]+secondNeighbs)) N = len(totalNeighb) if N==0: secondShell.append(ops[a]) else: secondShell.append(sum([ops[i] for i in totalNeighb])/N) ops = secondShell n=None mnop = min(ops) mxop = max(ops) if op in ["TET"]: mnop, mxop, n = 0.0, 1.0, 11
r"$P(Q_%s)$" % str(lval)], "CN": [r"Coordination Number", r"P(CN)"], "RDF": [r"R$(\AA)$", "#_Bonds"], "ADF": [r"$\theta(deg)$", "#_Bond_Angles"], "BA": [r"R$(\AA)$", r"$G_{%s}(r)$" % str(lval)], "SF": [r"Q$(\AA^{-1})$", r"S(Q)"] } if args.averageFlag: if op not in ["BO", "CN", "TN", "TET"]: t = zip(*[orderVals[i][1] for i in range(len(orderVals))]) avgy = map(lambda x: sum(x) / len(x), t) avgx = orderVals[0][0] elif op == "CN": hd, rcuts = zip(*orderVals) hd = [i for i in flatten(list(hd))] #flatten for averaging avgy, avgx, dummy = pl.hist(hd, bins=range(0, 16), visible=False, normed=True) avgx = avgx[:-1] pl.xlabel(xylabels["CN"][0]) pl.ylabel(xylabels["CN"][1]) if args.saveFlag: if op in ["TN", "TET"]: savetxt("AVERAGE." + op + str(lval), array([avgx, avgy]).T, delimiter=" ") elif op in ["ADF"]:
def types(outcarFile): nums = subprocess.check_output("head -n 1000 %s | grep ions\ per\ type "%outcarFile,shell=True).split("\n")[0].split("=")[1:] nums=map(int,nums) types = [j for j in flatten([[i]*nums[i] for i in range(len(nums))])] return types