示例#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
示例#2
0
    pl.hist(rsFlat,bins=[i/35.+0.5 for i in range(100)])
    pl.show()
    """

        #Plotting of atoms with bond radius.
        from mayavi import mlab
        fig=mlab.figure(bgcolor=(1.0,1.0,1.0))

        #coordination of atoms
        coord=map(lambda x: float(x.split()[0]), open(elfcarfile+".Coord","r").readlines()[1:])
        mx=max(coord)
        mn=min(coord)
        dl=mx-mn
        coord=map(lambda x: (x-mn)/dl,coord)
        mlab.points3d(atoms[:,0],atoms[:,1],atoms[:,2],coord,scale_factor=1.0,scale_mode='none')

        #bond radius
        mx=max(rsFlat)
        mn=min(rsFlat)
        dl=mx-mn
        for i,ineighbs in enumerate(neighbors):
            a=atoms[i]
            for i2,j in enumerate(ineighbs):
                b=minImageAtom(a,atoms[j],basis)
                c=(rs[i][i2]-mn)/dl
                mlab.plot3d([a[0],b[0]],[a[1],b[1]],[a[2],b[2]],color=(c,1-c,1-c),tube_radius=0.1,tube_sides=10)
        mlab.show()

    #need to do this plot separately
    pl.plot([a[0],b[0]],[a[1],b[1]],[a[2],b[2]],c=r/1.6,lw=10)
示例#3
0
        rlen.append(r)
        if r<3.2:
            mxLen=max(mxLen,rlen[-1])
            mnLen=min(mnLen,rlen[-1])
mnSoft,mxSoft=0.15,4.0
mnLen,mxLen = 2.40,2.9

pairs=list()
ds=list()
cs=list()
for i in range(nIon):
    d=0
    n=0
    for v,j in enumerate(neighbs[i]):
        r=dist_periodic(atoms[i],atoms[j],lengths)
        b=minImageAtom(atoms[i],atoms[j],basis)

        #if r<3.2:
        #Based on softness (blue is soft, red is not-soft)
        cSoft=(s2[i][v]-mnSoft)/(mxSoft-mnSoft)

        #Based on bond length
        cLen=(r-mnLen)/(mxLen-mnLen)

            #mlab.plot3d([atoms[i,0],b[0]],[atoms[i,1],b[1]],[atoms[i,2],b[2]],color=(1-cSoft,cSoft,cSoft),tube_radius=0.1,tube_sides=10)
            

            #mlab.plot3d([atoms[i,0],b[0]],[atoms[i,1],b[1]],[atoms[i,2],b[2]],color=(1-cLen,cLen,cLen),tube_radius=0.1,tube_sides=10)
            #mlab.plot3d([atoms[i,0],b[0]],[atoms[i,1],b[1]],[atoms[i,2],b[2]],color=(0.8,0.8,0.8),tube_radius=0.1,tube_sides=10)
        d+=cSoft
        n+=1
示例#4
0
        rlen.append(r)
        if r < 3.2:
            mxLen = max(mxLen, rlen[-1])
            mnLen = min(mnLen, rlen[-1])
mnSoft, mxSoft = 0.15, 4.0
mnLen, mxLen = 2.40, 2.9

pairs = list()
ds = list()
cs = list()
for i in range(nIon):
    d = 0
    n = 0
    for v, j in enumerate(neighbs[i]):
        r = dist_periodic(atoms[i], atoms[j], lengths)
        b = minImageAtom(atoms[i], atoms[j], basis)

        #if r<3.2:
        #Based on softness (blue is soft, red is not-soft)
        cSoft = (s2[i][v] - mnSoft) / (mxSoft - mnSoft)

        #Based on bond length
        cLen = (r - mnLen) / (mxLen - mnLen)

        #mlab.plot3d([atoms[i,0],b[0]],[atoms[i,1],b[1]],[atoms[i,2],b[2]],color=(1-cSoft,cSoft,cSoft),tube_radius=0.1,tube_sides=10)

        #mlab.plot3d([atoms[i,0],b[0]],[atoms[i,1],b[1]],[atoms[i,2],b[2]],color=(1-cLen,cLen,cLen),tube_radius=0.1,tube_sides=10)
        #mlab.plot3d([atoms[i,0],b[0]],[atoms[i,1],b[1]],[atoms[i,2],b[2]],color=(0.8,0.8,0.8),tube_radius=0.1,tube_sides=10)
        d += cSoft
        n += 1
    if n == 0:
示例#5
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
示例#6
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