Exemplo n.º 1
0
def elfcarBondAnalysis(elfcarFile,elfcarNeighbsFile,verbose=True):
    #Loads up an ELFCAR, generates a starting neighbor list from voronoi tesselation
    #Initial neighbors are dropped if bondlength is greater than maxBondLength
    #Generates a bunch of points on a cylinder
    #Maps the cylinder points across each neighbor pair
    #If the average ELF is always above minELF accross this cylinder, atoms are bonded.

    ELFlevel=0.5

    #Parse ELFCAR
    elfcar=open(elfcarFile,"r").readlines()
    (basis,atypes,atoms,header),elf = elfcarIO.read(elfcar)
    lengths=array([basis[0][0],basis[1][1],basis[2][2]])

    #Neighbors
    elfcarNeighbs=open(elfcarNeighbsFile,"r").readlines()
    neighbors=[map(int,line.split()) for line in elfcarNeighbs[1:]]
    halfNeighbs=full2half(neighbors)

    a=elf.shape
    AvgElf=sum([sum([sum(line) for line in plane]) for plane in elf])/a[0]/a[1]/a[2]
    if verbose:
        print elfcarFile
        print "Average ELF value:",AvgElf

    #Evaluate the ELF between each nieghbor pair
    #creates a bunch of points on a circle in the x-y plane
    def circlePoints(center,radius):
        N=11
        ps=[float(p)/N*radius for p in range(-N,N+1)]
        r2=radius*radius
        points=list()
        for x in ps:
            for y in ps:
                if (x**2+y**2)<=r2:
                    points.append(asarray([x,y]))
        return asarray(points)

    atoms=asarray([lengths[i]-v for i,v in enumerate(atoms.T)]).T

    #Flip the ELF because its off, thanks a lot VASP.
    elf=elf[::-1,::-1,::-1]

    #Loop over atom pairs
    cylRadius = 2.0
    cirPoints = circlePoints(a,cylRadius).T
    cirPoints = vstack([cirPoints,zeros(cirPoints.shape[1])]) 
    coordination=zeros(len(atoms))
    gridx,gridy=np.mgrid[0:1:20j,0:1:20j]*4.2-2.1
    cirPoints2=array(cirPoints)
    cirPoints2=cirPoints2[:2].T
    f,ax  =plt.subplots(1,1)
    rs=[list() for i in halfNeighbs]
    rsFlat=list()
    for i,ineighbs in enumerate(halfNeighbs):
        a=atoms[i]
        for j in ineighbs:
            #copy the cylinder points so you can play with them...
            localCir=array(cirPoints)

            #Find the minimum image atom
            b=minImageAtom(a,atoms[j],basis)
            l=minImageDist(a,b,basis)

            #How to map your cylinder onto the local atom
            R=rotmatx([0,0,l],b-a)

            #Loop over each cylinder slice
            sliceParam=list()
            localCir[2]=l/2.
            cir=asarray([dot(R,p)+a for p in localCir.T]).T
                
            #cir2 is circle with periodic boundary conditions applied and mapped to index space
            cir2=asarray([((c/lengths[ind]*elf.shape[ind])%(elf.shape[ind]-1)) for ind,c in enumerate(cir)])            

            #Interpolation across cylinder
            z=ndimage.map_coordinates(elf,cir2)

            #Generate a grid and find the desired contour on the bond crosssection
            gridz=interpolate.griddata(cirPoints2,z,(gridx,gridy),fill_value=0)
            ac=ax.contour(gridx,gridy,gridz,levels=[ELFlevel],linewidths=5,colors="black")

            #take the longest list (this is the bond)
            m=0
            if len(ac.collections[0].get_paths()):
                m=np.asarray([len(v.vertices) for v in ac.collections[0].get_paths()]).argmax()     
            midCircle= ac.collections[0].get_paths()[m].vertices.T
            n=midCircle.shape[1]

            #Find the center of the bond and calculate the radius
            com=[midCircle[0].sum()/n,midCircle[1].sum()/n]
            midCircle[0]-=com[0]
            midCircle[1]-=com[1]
            r=0
            for m in midCircle.T:
                r+=(m[0]**2+m[1]**2)**(0.5)
            r/=n
            rs[i].append(r)
            rs[j].append(r)
            rsFlat.append(r)

#                pl.contour(gridx,gridy,gridz,levels=[0.5],linewidths=5,colors="black")
#                pl.show()
            #avgCircle+=jCircle
    #avgCircle/=sum(map(len,neighbors))/2.
    
    #pl.show()
    return rs,rsFlat,atoms,neighbors,basis
Exemplo n.º 2
0
    print "Usage:"
    print "%s <ELFCAR> <bond-ELF-cutoff=0.5>" % (sys.argv[0])
    print "Note ELFCAR must be part of a cubic/rectangular simulation"


if len(sys.argv) < 2:
    usage()
    exit(0)

bondCutoffs = [float(i) / 10 for i in range(2, 7)]
if len(sys.argv) == 3:
    bondCutoffs = [float(sys.argv[2])]

#Parse ELFCAR
elfcar = open(sys.argv[1], "r").readlines()
(basis, atypes, atoms, header), gridSize, elf = elfcarIO.read(elfcar)
basis = array(basis)
bounds = [[0., basis[0][0]], [0., basis[1][1]], [0., basis[2][2]]]
atoms = array(atoms)

#Grid properties
nGridPoints = reduce(operator.mul, gridSize)

#Neighbors
halfNeighbors = voronoiNeighbors(atoms=atoms,
                                 basis=basis,
                                 atypes=atypes,
                                 style='half')

print "Number of Neighbors before elimination:", sum(
    [len(i) for i in halfNeighbors])
Exemplo n.º 3
0
import numpy as np
def usage():
    print "%s CHGCARfiles"%sys.argv[0].split("/")[-1]

if len(sys.argv)<2:
    usage()
    exit(0)

chgelfcarfiles = sorted(sys.argv[1:],key=lambda x:str(x.split("_")[-1]))
m=0
for chgelfcarfile in chgelfcarfiles:
    car=open(chgelfcarfile,"r").readlines()
    if "CHG" in chgelfcarfile:
        pcar,field = chgcarIO.read(car)
    if "ELF" in chgelfcarfile:
        pcar,field = elfcarIO.read(car)
    (basis,atypes,atoms,head)=pcar
    volume=np.dot(np.cross(basis[0],basis[1]),basis[2])/len(atoms)
    field=field.ravel()
    field=map(float,field.tolist())
    #field.sort()
    vals,bins,dummy=pl.hist(field,100,alpha=0.5,visible=False)
    s=sum(vals)
    vals=[v/s*100 for v in vals]
    m=max(m,max(vals))
    bins=map(lambda x:(x[0]+x[1])/2.,zip(bins[:-1],bins[1:]))
    pl.plot(bins,vals,label="Step: %s"%chgelfcarfile.split("_")[-1].split("/")[0]+"   Vol:%4.4f"%volume)
#pl.xticks([x/20.*2.5 - 0.5 for x in range(20)])
pl.ylabel("Percent Volume")
pl.xlabel("Charge (meV)")
pl.ylim([0,m*1.1])
Exemplo n.º 4
0
def elfcarNeighborAnalysis(elfcarfile,
                           verbose=False,
                           minELF=0.5,
                           maxBondLength=4.0):
    #Loads up an ELFCAR, generates a starting neighbor list from voronoi tesselation
    #Initial neighbors are dropped if bondlength is greater than maxBondLength
    #Generates a bunch of points on a cylinder
    #Maps the cylinder points across each neighbor pair
    #If the average ELF is always above minELF accross this cylinder, atoms are bonded.

    #Parse ELFCAR
    elfcar = open(elfcarfile, "r").readlines()
    (basis, atypes, atoms, header), elf = elfcarIO.read(elfcar)
    lengths = array([basis[0][0], basis[1][1], basis[2][2]])

    #Neighbors
    bounds = [[0, basis[0][0]], [0, basis[1][1]], [0, basis[2][2]]]
    halfNeighbs = voronoiNeighbors(atoms, basis, style="half")

    a = elf.shape
    AvgElf = sum([sum([sum(line) for line in plane])
                  for plane in elf]) / a[0] / a[1] / a[2]
    if verbose:
        print elfcarfile
        print "Average ELF value:", AvgElf

    #Evaluate the ELF between each nieghbor pair
    #creates a bunch of points on a circle in the x-y plane
    def circlePoints(center, radius):
        N = 4
        ps = [float(p) / N * radius for p in range(-N, N + 1)]
        r2 = radius * radius
        points = list()
        for x in ps:
            for y in ps:
                if (x**2 + y**2) <= r2:
                    points.append(asarray([x, y]))
        return asarray(points)

    atoms = asarray([lengths[i] - v for i, v in enumerate(atoms.T)]).T

    #Flip the ELF because its off, thanks a lot VASP.
    elf = elf[::-1, ::-1, ::-1]

    #Loop over atom pairs, generate cylinders
    cylSlices = 10
    cylRadius = 0.7
    cirPoints = circlePoints(a, cylRadius).T
    cylPoints = [
        vstack([cirPoints, zeros(cirPoints.shape[1]) + float(z)])
        for z in range(cylSlices + 1)
    ]
    coordination = zeros(len(atoms))
    neighborsELF = [list() for i in range(len(atoms))]

    for i, ineighbs in enumerate(halfNeighbs):
        a = atoms[i]

        for j in ineighbs:
            #copy the cylinder points so you can play with them...
            localCyl = array(cylPoints)

            #Find the minimum image atom
            b = minImageAtom(a, atoms[j], basis)
            l = minImageDist(a, b, basis)

            if l > maxBondLength or l == 0.0: continue

            #How to map your cylinder onto the local atom
            R = rotmatx([0, 0, l], b - a)

            #Loop over each cylinder slice
            sliceParam = list()
            for cir in localCyl:
                #cir is stretched and rotated cylinder
                cir[2] /= cylSlices / l
                cir = asarray([dot(R, p) + a for p in cir.T]).T

                #cir2 is cir with periodic boundary conditions applied and mapped to index space
                cir2 = asarray([((c / lengths[ind] * elf.shape[ind]) %
                                 (elf.shape[ind] - 1))
                                for ind, c in enumerate(cir)])

                #Interpolation across cylinder
                z = ndimage.map_coordinates(elf, cir2)

                #Average ELF value across each slice.
                sliceParam.append(sum(z) / len(z))

            if min(sliceParam) > minELF:
                #neighbor pair is bonded, count it!
                neighborsELF[i].append(j)
                neighborsELF[j].append(i)

    return neighborsELF
Exemplo n.º 5
0
    print "Usage:"
    print "%s <ELFCAR> <bond-ELF-cutoff=0.5>" % (sys.argv[0])
    print "Note ELFCAR must be part of a cubic/rectangular simulation"


if len(sys.argv) < 2:
    usage()
    exit(0)

bondCutoffs = [float(i) / 10 for i in range(2, 7)]
if len(sys.argv) == 3:
    bondCutoffs = [float(sys.argv[2])]

# Parse ELFCAR
elfcar = open(sys.argv[1], "r").readlines()
(basis, atypes, atoms, header), gridSize, elf = elfcarIO.read(elfcar)
basis = array(basis)
bounds = [[0.0, basis[0][0]], [0.0, basis[1][1]], [0.0, basis[2][2]]]
atoms = array(atoms)

# Grid properties
nGridPoints = reduce(operator.mul, gridSize)

# Neighbors
halfNeighbors = voronoiNeighbors(atoms=atoms, basis=basis, atypes=atypes, style="half")

print "Number of Neighbors before elimination:", sum([len(i) for i in halfNeighbors])

a = elf.shape
print "Average ELF value:", sum([sum([sum(line) / a[2] for line in plane]) / a[1] for plane in elf]) / a[0]
Exemplo n.º 6
0
if len(sys.argv) < 3:
    usage()

elfcar = open(sys.argv[1],"r").readlines()
pstyle = int(sys.argv[2])

#If saving a picture, assume remote use which requires Agg
if pstyle==0:
    fname=sys.argv[3]
    matplotlib.use("Agg")
else:
    from matplotlib import pyplot as P
import pylab as pl

global dataset
(basis,types,atoms,header),gridsz,dataset = elfcarIO.read(elfcar)

Npnts = reduce(operator.mul,gridsz)

#VASP outputs CHGCAR/ELFCARs in the order Z,Y,X.  Transfrom this to X,Y,Z
dataset=array(dataset).reshape(list(reversed(gridsz))) #[x,y,z]
dataset=dataset.swapaxes(0,2)
#dataset=log(dataset)
global atoms,atomcolors,atombounds
#Ge: 1.22 
#Sb: 1.4
#Te: 1.4
#Au: 1.35
#Cu: 1.4
#Ce: 1.8
radii=[0.7]
Exemplo n.º 7
0
def elfcarNeighborAnalysis(elfcarfile,verbose=False,minELF=0.5,maxBondLength=4.0):
    #Loads up an ELFCAR, generates a starting neighbor list from voronoi tesselation
    #Initial neighbors are dropped if bondlength is greater than maxBondLength
    #Generates a bunch of points on a cylinder
    #Maps the cylinder points across each neighbor pair
    #If the average ELF is always above minELF accross this cylinder, atoms are bonded.

    #Parse ELFCAR
    elfcar=open(elfcarfile,"r").readlines()
    (basis,atypes,atoms,header),elf = elfcarIO.read(elfcar)
    lengths=array([basis[0][0],basis[1][1],basis[2][2]])

    #Neighbors
    bounds=[[0,basis[0][0]],[0,basis[1][1]],[0,basis[2][2]]]
    halfNeighbs = voronoiNeighbors(atoms,basis,style="half")

    a=elf.shape
    AvgElf=sum([sum([sum(line) for line in plane]) for plane in elf])/a[0]/a[1]/a[2]
    if verbose:
        print elfcarfile
        print "Average ELF value:",AvgElf

    #Evaluate the ELF between each nieghbor pair
    #creates a bunch of points on a circle in the x-y plane
    def circlePoints(center,radius):
        N=4
        ps=[float(p)/N*radius for p in range(-N,N+1)]
        r2=radius*radius
        points=list()
        for x in ps:
            for y in ps:
                if (x**2+y**2)<=r2:
                    points.append(asarray([x,y]))
        return asarray(points)

    atoms=asarray([lengths[i]-v for i,v in enumerate(atoms.T)]).T

    #Flip the ELF because its off, thanks a lot VASP.
    elf=elf[::-1,::-1,::-1]

    #Loop over atom pairs, generate cylinders
    cylSlices = 10   
    cylRadius = 0.7
    cirPoints = circlePoints(a,cylRadius).T
    cylPoints = [vstack([cirPoints,zeros(cirPoints.shape[1])+float(z)]) for z in range(cylSlices+1)]
    coordination=zeros(len(atoms))
    neighborsELF=[list() for i in range(len(atoms))]

    for i,ineighbs in enumerate(halfNeighbs):
        a=atoms[i]

        for j in ineighbs:
            #copy the cylinder points so you can play with them...
            localCyl=array(cylPoints)

            #Find the minimum image atom
            b=minImageAtom(a,atoms[j],basis)
            l=minImageDist(a,b,basis)

            if l>maxBondLength or l==0.0: continue

            #How to map your cylinder onto the local atom
            R=rotmatx([0,0,l],b-a)

            #Loop over each cylinder slice
            sliceParam=list()
            for cir in localCyl:
                #cir is stretched and rotated cylinder
                cir[2]/=cylSlices/l
                cir=asarray([dot(R,p)+a for p in cir.T]).T
                
                #cir2 is cir with periodic boundary conditions applied and mapped to index space
                cir2=asarray([((c/lengths[ind]*elf.shape[ind])%(elf.shape[ind]-1)) for ind,c in enumerate(cir)])            

                #Interpolation across cylinder
                z=ndimage.map_coordinates(elf,cir2)

                #Average ELF value across each slice.
                sliceParam.append(sum(z)/len(z))

            if min(sliceParam)>minELF:
                #neighbor pair is bonded, count it!
                neighborsELF[i].append(j)
                neighborsELF[j].append(i)

    return neighborsELF