Esempio n. 1
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
Esempio n. 2
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
Esempio n. 3
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