def unFractional(posfile): [basis,atypes,atoms,head,poscar] = poscarIO.read(open(posfile,"r").readlines(),frac_coord=True) xs,ys,zs = zip(*atoms) if sum(xs)/len(xs)>1.0 or sum(ys)/len(ys)>1.0 or sum(zs)/len(zs)>1.0: print "Error: it appears these are already unfractional coordinates. %s"%posfile exit(0) [basis,atypes,atoms,head,poscar] = poscarIO.read(open(posfile,"r").readlines(),frac_coord=False) poscarIO.write(posfile,basis, atoms,atypes,head,frac=True,autoFrac=False)
def poscar2dump(pcarFile, lmpFile, scale=None): try: poscar = open(pcarFile, "r").readlines() lammps = open(lmpFile, "w") except IOError: print "Error: %s Unable to open POSCAR/Lammps file." % sys.argv[0].split("/")[-1] usage() exit(0) if scale == None: scale = 1.0 [basis, atypes, atoms, head, poscar] = poscarIO.read(poscar) # Convert from POSCAR style basis vectors to LAMMPS style boundaries. xhi, yhi, zhi, xy, xz, yz = basis2lohi(basis) basis = matrix([[xhi, 0, 0], [xy, yhi, 0], [xz, yz, zhi]]) N = sum(atypes) Ntypes = len(atypes) types = [i for i in flatten([[i] * v for i, v in enumerate(atypes)])] data = "#Generated by %s from %s\n\n" % (sys.argv[0].split("/")[-1], pcarFile) data += "%d atoms\n" % N data += "%d atom types\n\n" % Ntypes data += "0.0000 %4f xlo xhi\n" % xhi data += "0.0000 %4f ylo yhi\n" % yhi data += "0.0000 %4f zlo zhi\n" % zhi data += "% 4f % 4f % 4f xy xz yz\n\n" % (xy, xz, yz) data += "Atoms\n\n" for i, (t, atom) in enumerate(zip(types, atoms)): x, y, z = atom # (atom*basis).tolist()[0] data += "\t %d \t %d \t % 5f\t% 5f\t% 5f\n" % (i + 1, t + 1, x, y, z) lammps.write(data) lammps.close()
def fractional(posfile): [basis,atypes,atoms,head,poscar] = poscarIO.read(open(posfile,"r").readlines(),frac_coord=True) fraced=False xs,ys,zs = zip(*atoms) if sum(xs)/len(xs)>1.0 or sum(ys)/len(ys)>1.0 or sum(zs)/len(zs)>1.0: fraced=True if not fraced: print "Error: it appears these are already fractional coordiantes. %s"%posfile exit(0) poscarIO.write(posfile,basis,atoms,atypes,head,frac=True)
def unFractional(posfile): [basis, atypes, atoms, head, poscar] = poscarIO.read(open(posfile, "r").readlines(), frac_coord=True) xs, ys, zs = zip(*atoms) if sum(xs) / len(xs) > 1.0 or sum(ys) / len(ys) > 1.0 or sum(zs) / len( zs) > 1.0: print "Error: it appears these are already unfractional coordinates. %s" % posfile exit(0) [basis, atypes, atoms, head, poscar] = poscarIO.read(open(posfile, "r").readlines(), frac_coord=False) poscarIO.write(posfile, basis, atoms, atypes, head, frac=True, autoFrac=False)
def fractional(posfile): [basis, atypes, atoms, head, poscar] = poscarIO.read(open(posfile, "r").readlines(), frac_coord=True) fraced = False xs, ys, zs = zip(*atoms) if sum(xs) / len(xs) > 1.0 or sum(ys) / len(ys) > 1.0 or sum(zs) / len( zs) > 1.0: fraced = True if not fraced: print "Error: it appears these are already fractional coordiantes. %s" % posfile exit(0) poscarIO.write(posfile, basis, atoms, atypes, head, frac=True)
def read(elfcar,swapxz=True): basis,types,atoms,header,elfcar=poscarIO.read(elfcar) atoms=asarray(atoms) basis=asarray(basis) poscardata=(basis,types,atoms,header) elfcar.pop(0) gridsz=[int(i) for i in elfcar.pop(0).split()] if swapxz: gridsz=[gridsz[2],gridsz[1],gridsz[0]] Tot_pnts = reduce(operator.mul,gridsz) elfdata=asarray(map(float,"".join(elfcar).split()[:Tot_pnts])) elfdata.shape=gridsz if swapxz: elfdata=elfdata.swapaxes(0,2) return poscardata,elfdata
def read(elfcar, swapxz=True): basis, types, atoms, header, elfcar = poscarIO.read(elfcar) atoms = asarray(atoms) basis = asarray(basis) poscardata = (basis, types, atoms, header) elfcar.pop(0) gridsz = [int(i) for i in elfcar.pop(0).split()] if swapxz: gridsz = [gridsz[2], gridsz[1], gridsz[0]] Tot_pnts = reduce(operator.mul, gridsz) elfdata = asarray(map(float, "".join(elfcar).split()[:Tot_pnts])) elfdata.shape = gridsz if swapxz: elfdata = elfdata.swapaxes(0, 2) return poscardata, elfdata
def read(chgcar, SP=False, frac_coord=True, swapxz=True): basis, types, atoms, header, chgcar = poscarIO.read(chgcar, frac_coord) poscardata = (basis, types, atoms, header) chgcar.pop(0) gridsz = map(int, chgcar.pop(0).split()) Tot_pnts = reduce(operator.mul, gridsz) npline = len(chgcar[0].split()) cur = Tot_pnts / npline if cur * npline < Tot_pnts: cur += 1 #Divices by Tot_pnts to get absolute Charge (e.g. total # electrons) chgdata = array( map(lambda x: float(x) / Tot_pnts, "".join(chgcar[:cur]).split())) if swapxz: gridsz = [gridsz[2], gridsz[1], gridsz[0]] chgdata.shape = gridsz chgcar = chgcar[cur:] #Spin polarized chgcar, first half is chgdata-summed, second is subtracted if SP: if len(chgcar) > 0: chgdata_add = chgdata chgcar = chgcar[2:] chgdata_sub = array( map(lambda x: float(x) / Tot_pnts, "".join(chgcar[:cur]).split())) chgdata_sub.shape = gridsz else: print "WARNING: Requested Spin-Polarized CHGCAR read from a non-spin polarized CHGCAR file." SP = False #To eliminate points that step outside a reasonable range #avg = sum(chgdata)/len(chgdata) #chgdata[where(chgdata > 3*avg)[0]]=avg #Some chgcars seem to need their axes swapped, possible bug in VASP if swapxz: chgdata = swapaxes(chgdata, 0, 2) if SP: return poscardata, chgdata_add, chgdata_sub return poscardata, chgdata
def read(chgcar,SP=False,frac_coord=True,swapxz=True): basis,types,atoms,header,chgcar=poscarIO.read(chgcar,frac_coord) poscardata=(basis,types,atoms,header) chgcar.pop(0) gridsz=map(int,chgcar.pop(0).split()) Tot_pnts = reduce(operator.mul,gridsz) npline=len(chgcar[0].split()) cur=Tot_pnts/npline if cur*npline<Tot_pnts: cur+=1 #Divices by Tot_pnts to get absolute Charge (e.g. total # electrons) chgdata=array(map(lambda x:float(x)/Tot_pnts,"".join(chgcar[:cur]).split())) if swapxz: gridsz=[gridsz[2],gridsz[1],gridsz[0]] chgdata.shape=gridsz chgcar=chgcar[cur:] #Spin polarized chgcar, first half is chgdata-summed, second is subtracted if SP: if len(chgcar)>0: chgdata_add=chgdata chgcar = chgcar[2:] chgdata_sub=array(map(lambda x:float(x)/Tot_pnts,"".join(chgcar[:cur]).split())) chgdata_sub.shape=gridsz else: print "WARNING: Requested Spin-Polarized CHGCAR read from a non-spin polarized CHGCAR file." SP=False #To eliminate points that step outside a reasonable range #avg = sum(chgdata)/len(chgdata) #chgdata[where(chgdata > 3*avg)[0]]=avg #Some chgcars seem to need their axes swapped, possible bug in VASP if swapxz: chgdata=swapaxes(chgdata,0,2) if SP: return poscardata,chgdata_add,chgdata_sub return poscardata,chgdata
def poscar2dump(pcarFile, lmpFile, scale=None): try: poscar = open(pcarFile, "r").readlines() lammps = open(lmpFile, "w") except IOError: print "Error: %s Unable to open POSCAR/Lammps file." % sys.argv[ 0].split("/")[-1] usage() exit(0) if scale == None: scale = 1.0 [basis, atypes, atoms, head, poscar] = poscarIO.read(poscar) #Convert from POSCAR style basis vectors to LAMMPS style boundaries. xhi, yhi, zhi, xy, xz, yz = basis2lohi(basis) basis = matrix([[xhi, 0, 0], [xy, yhi, 0], [xz, yz, zhi]]) N = sum(atypes) Ntypes = len(atypes) types = [i for i in flatten([[i] * v for i, v in enumerate(atypes)])] data = "#Generated by %s from %s\n\n" % (sys.argv[0].split("/")[-1], pcarFile) data += "%d atoms\n" % N data += "%d atom types\n\n" % Ntypes data += "0.0000 %4f xlo xhi\n" % xhi data += "0.0000 %4f ylo yhi\n" % yhi data += "0.0000 %4f zlo zhi\n" % zhi data += "% 4f % 4f % 4f xy xz yz\n\n" % (xy, xz, yz) data += "Atoms\n\n" for i, (t, atom) in enumerate(zip(types, atoms)): x, y, z = atom #(atom*basis).tolist()[0] data += "\t %d \t %d \t % 5f\t% 5f\t% 5f\n" % (i + 1, t + 1, x, y, z) lammps.write(data) lammps.close()
#Reading in the options and preparing for file reading if len(sys.argv) < 2: usage() 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):
numbins = 1000 pcfile = "PCDAT_fromX" if len(sys.argv) < 3: usage() exit(0) if len(sys.argv) >= 4: cutoff = float(sys.argv[3]) if len(sys.argv) >= 5: numbins = int(sys.argv[4]) if len(sys.argv) == 6: pcfile = sys.argv[5] xdatfile = sys.argv[1] pcarfile = sys.argv[2] basis = poscarIO.read(open(pcarfile, "r").readlines())[0] xdatcar = open(xdatfile, "r").readlines() Natoms = int(xdatcar[0].split()[0]) lengths = array(map(lambda x: float(x) * 1e10, xdatcar[1].split()[1:4])) xdatcar = xdatcar[5:] delr = float(cutoff) / numbins pcors = list() i = 0 cnt = 0 atomconfigs = list() while i < len(xdatcar): i += 1 cnt += 1 atoms = map(lambda x: map(float, x.split()), xdatcar[i : i + Natoms])
iQ = array([simps([Q[abs(ir-it)]*dQ[it] for it,t in enumerate(rads[ir:])],x=rads[ir:]) for ir,r in enumerate(rads)]) return (-dQ + 2.0*pi*density*iQ)/rads def sq_calc(rads,cr,qs): dx = rads[1]-rads[0] cq = array([ 4*pi*simps(rads*cr*np.sin(q*rads)/q,dx=dx) for q in qs]) return 1./(1. - density*cq) def residual_qhr(coefs,y,x): Q = interp(dx,coefs,x) hr = y return x*hr - hrq_calc(dr,Q,hr,x) basis,atypes,atoms,head,poscar = poscarIO.read(open(sys.argv[1]).readlines()) atoms=array(atoms) basis=array(basis) rads,gr = radialDistribution(atoms,basis) rads = array(rads) hr = wsmooth(gr)[:-1] - 1#superSmooth(rads,gr)[:-20] - 1 #hr = gr - 1 dr=rads[1]-rads[0] density = atoms.shape[0]/dot(cross(basis[0],basis[1]),basis[2]) rcut = rads[-1] radsCut = [i for i in rads if i <= rcut] hrCut = [hr[i] for i in range(len(rads)) if rads[i] <= rcut] Nknots=70
print "Usage:" print "%s <directory containing OUTCAR & POSCAR, or just POSCAR file> <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)<2: usage() 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):
import poscarIO def usage(): print "Usage:" print "%s <elfcarfile> <elf cutoff [0-1]>"%sys.argv[0] print "Plotting Styles: 0=none, 1=chg contours, 2=vacancy contours, 3=make a bunch of plots for a movie,\n4=chg contours with atoms, 5=make a bunch of plots for a movie with spheres" exit(0) if not(len(sys.argv) in [3,4]): usage() elfcar = open(sys.argv[1],"r").readlines() cutev = float(sys.argv[2]) pstyle = int(sys.argv[3]) basis,types,catoms,header,elfcar = poscarIO.read(elfcar) elfcar.pop(0) gridsz=[int(i) for i in elfcar.pop(0).split()] Tot_pnts = reduce(operator.mul,gridsz) dataset=list() for line in elfcar: dataset+=[float(i) for i in line.split()] dataset=dataset[:Tot_pnts] #chop off extra, invalid values #Convert the dataset from charge density to vacancy #def vval(a,b): return 1 if a<b else 0 #vacData=[vval(i,cutev) for i in dataset] #nvacays=sum(vacData)
def usage(): print "Usage:" print "%s <elfcarfile> <elf cutoff [0-1]>" % sys.argv[0] print "Plotting Styles: 0=none, 1=chg contours, 2=vacancy contours, 3=make a bunch of plots for a movie,\n4=chg contours with atoms, 5=make a bunch of plots for a movie with spheres" exit(0) if not (len(sys.argv) in [3, 4]): usage() elfcar = open(sys.argv[1], "r").readlines() cutev = float(sys.argv[2]) pstyle = int(sys.argv[3]) basis, types, catoms, header, elfcar = poscarIO.read(elfcar) elfcar.pop(0) gridsz = [int(i) for i in elfcar.pop(0).split()] Tot_pnts = reduce(operator.mul, gridsz) dataset = list() for line in elfcar: dataset += [float(i) for i in line.split()] dataset = dataset[:Tot_pnts] #chop off extra, invalid values #Convert the dataset from charge density to vacancy #def vval(a,b): return 1 if a<b else 0 #vacData=[vval(i,cutev) for i in dataset] #nvacays=sum(vacData)
lammpsFlag=False xdatcarFlag=False if "OUTCAR" in filename: outcarFlag=True elif "XDATCAR" in filename: xdatcarFlag=True poscarFile = sys.argv[3] else: lammpsFlag=True neighbsfile=filename+".neighb" header=["Spaces Seperate Neighbs, Commas Seperate Atoms, Lines Seperate Arrangements\n"] lines=header if xdatcarFlag: basis,dummy,atoms,dummy,dummy = poscarIO.read(poscarFile) nAtoms = len(atoms) bounds = [[0,1],[0,1],[0,1]] rcut /= basis[0][0] for i,atoms in enumerate(xdatcarIO.read2(filename)): neighbs = neighbors.neighbors(atoms,bounds,rcut) lines += [",".join([" ".join(map(str,atomn)) for atomn in neighbs])+"\n"] if outcarFlag: nAtoms = outcarIO.nAtoms(filename) basis = array(map(array,outcarIO.basis(filename))) bounds = [[0,basis[0][0]],[0,basis[1][1]],[0,basis[2][2]]] #Find the starting locations of atomic data in outcarfile grepResults = subprocess.check_output("grep -b POSITION %s"%filename,shell=True).split("\n") bytenums=[int(i.split(":")[0]) for i in grepResults if len(i)>2]
op = sys.argv[1] if op[:2]=="BO": lval=int(op[-1]) op="BO" opFlag = True configFile=sys.argv[2] else: usage() exit(0) #Parse POSCAR j=0 if "POSCAR" in configFile or "CONTCAR" in configFile: poscar=open(configFile,"r").readlines() [basis,atypes,atoms,head,poscar] = poscarIO.read(poscar) types=list() for i in atypes: types+=[j+1]*i j+=1 elif "OUTCAR" in configFile: TE,stress,basis,atoms,forces,types = outcarIO.outcarReadConfig(configFile,Nconfig) #Parse LAMMPS DUMP else: basis,types,atoms = lammpsIO.readConfig(configFile,Nconfig) ax,ay,az=map(np.array,zip(*atoms)) v1,v2,v3=basis
cutoff = 10.0 numbins = 1000 pcfile = "PCDAT_fromX" if len(sys.argv) < 3: usage() exit(0) if len(sys.argv) >= 4: cutoff = float(sys.argv[3]) if len(sys.argv) >= 5: numbins = int(sys.argv[4]) if len(sys.argv) == 6: pcfile = sys.argv[5] xdatfile = sys.argv[1] pcarfile = sys.argv[2] basis = poscarIO.read(open(pcarfile, "r").readlines())[0] xdatcar = open(xdatfile, "r").readlines() Natoms = int(xdatcar[0].split()[0]) lengths = array(map(lambda x: float(x) * 1E10, xdatcar[1].split()[1:4])) xdatcar = xdatcar[5:] delr = float(cutoff) / numbins pcors = list() i = 0 cnt = 0 atomconfigs = list() while i < len(xdatcar): i += 1 cnt += 1 atoms = map(lambda x: map(float, x.split()), xdatcar[i:i + Natoms])
def sq_calc(rads, cr, qs): dx = rads[1] - rads[0] cq = array( [4 * pi * simps(rads * cr * np.sin(q * rads) / q, dx=dx) for q in qs]) return 1. / (1. - density * cq) def residual_qhr(coefs, y, x): Q = interp(dx, coefs, x) hr = y return x * hr - hrq_calc(dr, Q, hr, x) basis, atypes, atoms, head, poscar = poscarIO.read( open(sys.argv[1]).readlines()) atoms = array(atoms) basis = array(basis) rads, gr = radialDistribution(atoms, basis) rads = array(rads) hr = wsmooth(gr)[:-1] - 1 #superSmooth(rads,gr)[:-20] - 1 #hr = gr - 1 dr = rads[1] - rads[0] density = atoms.shape[0] / dot(cross(basis[0], basis[1]), basis[2]) rcut = rads[-1] radsCut = [i for i in rads if i <= rcut] hrCut = [hr[i] for i in range(len(rads)) if rads[i] <= rcut] Nknots = 70
v0_0 ... ... vMN_0 ... #instead of vertices, writing vertex coordinates """ if len(sys.argv)<4: usage() exit(0) qvodata=open(sys.argv[1],"r").readlines() qvfidata=open(sys.argv[2],"r").readlines() poscar=open(sys.argv[3],"r").readlines() [basis,atypes,atoms,head,poscar] = poscarIO.read(poscar) basis=array(basis) bounds=array([basis[0][0],basis[1][1],basis[2][2]]) polyverts=readQVo(qvodata)#,bounds) polyplanes,neighbors=readQVFi(qvfidata) #Chop off polyhedra of points outside simulation polyplanes=polyplanes[:len(atoms)] polyhedra=[points2polyhedron(verts,planes,plotting=False) for verts,planes in zip(polyverts,polyplanes)] polyverts=readQVo(qvodata) polyplanes,neighbors=readQVFi(qvfidata) polyhedra=[points2polyhedron(verts,planes,plotting=False) for verts,planes in zip(polyverts[0:100],polyplanes[0:100])]
def poscarGrow(poscarName,outputName,cx,cy,cz): poscar=open(poscarName,"r").readlines() nCopies=cx*cy*cz [basis,atypes,atoms,head,poscar] = poscarIO.read(poscar,frac_coord=True) natoms=len(atoms) v1,v2,v3=map(array,basis) ax,ay,az=map(array,zip(*atoms)) #duplicate and tile ax=array(split(tile(ax,nCopies),nCopies)) ay=array(split(tile(ay,nCopies),nCopies)) az=array(split(tile(az,nCopies),nCopies)) #Shift tiles in x dirn shift=array([1]*natoms) shiftfull=array([shift*j for j in range(cx)]) for i in range(cy*cz): ax[i*cx+array(range(cx))]+=shiftfull #Shift tiles in y dirn shift=array([1]*natoms) shiftfull=array([shift*(j/cx) for j in range(cy*cx)]) for i in range(cz): ay[i*cx*cy+array(range(cy*cx))]+=shiftfull #Shift tiles in z dirn shift=array([1]*natoms) shiftfull=array([shift*(j/cx/cy) for j in range(cy*cx*cz)]) az+=shiftfull ax=ax.reshape([nCopies*natoms]) ay=ay.reshape([nCopies*natoms]) az=az.reshape([nCopies*natoms]) #need to normalize with new positions with respect to duplicated lattice params v1*=cx v2*=cy v3*=cz basis=[v1,v2,v3] A=matrix([[float(cx),0.0,0.0],[0.0,float(cy),0.0],[0.0,0.0,float(cz)]]) ax,ay,az=zip(*[linalg.solve(A,array(p).T)[:] for p in zip(ax,ay,az)]) # if max(ax)>1.0 or max(ay)>1.0 or max(az)>1.0: # continue # exit(0) atoms=zip(ax,ay,az) #Sort atoms by type, as required by POSCAR types=list() j=0 for i in atypes: types+=[j+1]*i j+=1 newtypes=types*cx*cy*cz atoms,types=zip(*sorted(zip(atoms,newtypes),key=lambda x:x[1])) atypes=[i*nCopies for i in atypes] poscarIO.write(outputName,basis,atoms,atypes,head) return len(atoms),basis
qvfp.write("% 6.6f % 6.6f % 6.6f\n"%(atom[0],atom[1],atom[2])) qvfp.flush() qvfp.close() return qvfile,basis,datoms,NRealAtoms if __name__=="__main__": def usage(): print "Usage: %s <poscar/contcar> <QV filename>"%sys.argv[0] print "Makes a QV_input file from the poscar/contcar file. Employs periodic boundary conditions." if len(sys.argv)<2: usage() exit(0) poscarFile=open(sys.argv[1],"r").readlines() basis,atypes,atoms,head,poscar = poscarIO.read(poscarFile) qvfile=None if len(sys.argv)>=3: qvfile=sys.argv[2] dummy,basis,datoms,nreal=poscar2qvoronoi(atoms,basis,atypes,qvfile) else: dummy,basis,datoms,nreal=poscar2qvoronoi(atoms,basis,atypes) print "Bounds of simulation area are:" for i in basis: print i print "Make sure to remove excess atoms outside these bounds after analysis."
if __name__ == "__main__": def usage(): print "Usage:" print "%s <POSCAR> //prints volume and atomic volume" print "%s <POSCAR> <frac/unfrac>" % sys.argv[0].split("/")[-1] print "%s <POSCAR> <ratio value>" % sys.argv[0].split("/")[-1] if len(sys.argv) not in [2, 3]: usage() exit(0) if len(sys.argv) == 2: [basis, atypes, atoms, head, poscar] = poscarIO.read(open(sys.argv[1], "r").readlines()) v = volume(basis) print "Total Volume in AA^3 = %f" % v print "Atomic Volume in AA^3 = %f" % (v / len(atoms)) elif sys.argv[2] == "frac": fractional(sys.argv[1]) elif sys.argv[2] == "unfrac": unFractional(sys.argv[1]) else: try: r = float(sys.argv[2]) ratio(sys.argv[1], r) except: print "Error, unrecognized volume arguement: %s" % sys.argv[2] usage() exit(0)