示例#1
0
def chgcarBondAnalysis(chgcarfile,
                       bondLengths,
                       normalize=False,
                       verbose=False,
                       Ninterps=None,
                       loc=None):

    BLs = bondLengths
    nBLs = len(BLs)

    #Parse CHGCAR
    chgcar = open(chgcarfile, "r").readlines()
    (v1, v2, v3, atypes, axs, ays, azs, header), chg = chgcarIO.read(chgcar)
    gridSize = chg.shape
    basis = asarray([v1, v2, v3])
    lengths = array([v1[0], v2[1], v3[2]])
    atoms = array(zip(axs, ays, azs))

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

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

    a = chg.shape
    AvgChg = sum([sum([sum(line) for line in plane])
                  for plane in chg]) / a[0] / a[1] / a[2]
    if verbose:
        print "Average CHG value:", AvgChg

    #Evaluate the CHG between each nieghbor pair
    if Ninterps == None:
        Ninterps = array([1, 50, 50])
        avgGrids, grids, bondcounts = fieldNeighbors3D(atoms,
                                                       atypes,
                                                       basis,
                                                       chg,
                                                       gridSize,
                                                       halfNeighbors,
                                                       cutoffs=bondLengths,
                                                       loc=loc)
    else:
        Ninterps = array([1] + Ninterps)
        avgGrids, grids, bondcounts = fieldNeighbors3D(atoms,
                                                       atypes,
                                                       basis,
                                                       chg,
                                                       gridSize,
                                                       halfNeighbors,
                                                       cutoffs=bondLengths,
                                                       Ninterps=Ninterps,
                                                       loc=loc)

    #Normalize if necessary
    if normalize:
        avgGrids = [avgGrid / AvgChg for avgGrid in avgGrids]

    return avgGrids, grids, bondcounts
    """
示例#2
0
def chgcarBondAnalysis(chgcarfile,bondLengths,normalize=False,verbose=False,Ninterps=None,loc=None):

    BLs=bondLengths
    nBLs=len(BLs)

    #Parse CHGCAR
    chgcar=open(chgcarfile,"r").readlines()
    (v1,v2,v3,atypes,axs,ays,azs,header),chg = chgcarIO.read(chgcar)
    gridSize = chg.shape
    basis=asarray([v1,v2,v3])
    lengths=array([v1[0],v2[1],v3[2]])
    atoms=array(zip(axs,ays,azs))

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

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

    a=chg.shape
    AvgChg=sum([sum([sum(line) for line in plane]) for plane in chg])/a[0]/a[1]/a[2]
    if verbose:
        print "Average CHG value:",AvgChg

    #Evaluate the CHG between each nieghbor pair
    if Ninterps==None:
        Ninterps=array([1,50,50])
        avgGrids,grids,bondcounts=fieldNeighbors3D(atoms,atypes,basis,chg,gridSize,halfNeighbors,cutoffs=bondLengths,loc=loc)
    else:
        Ninterps=array([1]+Ninterps)
        avgGrids,grids,bondcounts=fieldNeighbors3D(atoms,atypes,basis,chg,gridSize,halfNeighbors,cutoffs=bondLengths,Ninterps=Ninterps,loc=loc)

    #Normalize if necessary
    if normalize:
        avgGrids=[avgGrid/AvgChg for avgGrid in avgGrids]
            
    return avgGrids,grids,bondcounts

    """
示例#3
0
        exit(0)

    chgcarfiles = sys.argv[1].split(",")
    bondLengths = map(float, sys.argv[2].split(","))
    normalize = False
    if len(sys.argv) > 3:
        if sys.argv[3][0] in ["n", "N"]:
            normalize = True
    verbose = True

    Ninterps = [15, 15, 15]
    if len(sys.argv) > 4:
        Ninterps = map(int, sys.argv[4].split(","))

    for chgcarfile in chgcarfiles:

        avgGrids, bondCounts = chgcarBondAnalysis(chgcarfile,
                                                  bondLengths,
                                                  normalize,
                                                  verbose,
                                                  Ninterps=Ninterps)

        chgcar = open(chgcarfile, "r").readlines()
        poscardata, gridSize, chg = chgcarIO.read(chgcar)

        for avgGrid, bondCount, cutoff in zip(avgGrids, bondCounts,
                                              bondLengths):
            vtkfname = chgcarfile + "_cut%2.2f_NBond%d.vtk" % (cutoff,
                                                               bondCount)
            chgcarIO.writeVTK(vtkfname, poscardata, avgGrid.shape, avgGrid)
示例#4
0
def usage():
    print "Usage:"
    print "%s <chgfile> <charge cutoff (eV)> <plotting style: 0,1,2>"%sys.argv[0]
    print "Plotting Styles: 0=none, 1=chg contours, 2=vacancy contours"
    sys.exit()

if not(len(sys.argv) in [3,4]):
    usage()

chgcar = open(sys.argv[1],"r").readlines()
cutev = float(sys.argv[2])
pstyle = int(sys.argv[3])

global dataset
(basis,types,atoms,header),gridsz,dataset = chgcarIO.read(chgcar)
#dataset.shape=gridsz[0]*gridsz[1]*gridsz[2]

Tot_pnts = reduce(operator.mul,gridsz)

#dataset=vclearout(dataset,avgval*3)
#dataset=array([log(i/avgval) for i in dataset])
#dataset is 1d
#dhist=pl.hist(dataset,bins=10000,range=(0,1000),normed=True,histtype='step')[0]
#f=open("CHGDENS_HIST","w")
#pickle.dump(dhist,f)
#f.close()

#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]
示例#5
0
    print "Usage:"
    print "%s <chgfile> <charge cutoff (eV)> <plotting style: 0,1,2>" % sys.argv[
        0]
    print "Plotting Styles: 0=none, 1=chg contours, 2=vacancy contours"
    sys.exit()


if not (len(sys.argv) in [3, 4]):
    usage()

chgcar = open(sys.argv[1], "r").readlines()
cutev = float(sys.argv[2])
pstyle = int(sys.argv[3])

global dataset
(basis, types, atoms, header), gridsz, dataset = chgcarIO.read(chgcar)
#dataset.shape=gridsz[0]*gridsz[1]*gridsz[2]

Tot_pnts = reduce(operator.mul, gridsz)

#dataset=vclearout(dataset,avgval*3)
#dataset=array([log(i/avgval) for i in dataset])
#dataset is 1d
#dhist=pl.hist(dataset,bins=10000,range=(0,1000),normed=True,histtype='step')[0]
#f=open("CHGDENS_HIST","w")
#pickle.dump(dhist,f)
#f.close()

#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]
示例#6
0
from vtk import *
#mine
import chgcarIO

def usage():
    print "Usage:"
    print "%s <chg-vtk-file>"%sys.argv[0]
    sys.exit()

if not(len(sys.argv) in [2]):
    usage()

fname=sys.argv[1]
vtkfile=fname+".vtk"

poscarData,chgcarData=chgcarIO.read(open(fname,"r").readlines(),swapxz=False)
chgcarIO.writeVTK(vtkfile,poscarData,chgcarData)

#---------------------------------
#Below is taken from website
#x---------------------------------
# Interaction with an Isosurface visualization

# A reader
reader = vtkStructuredPointsReader()
reader.SetFileName(vtkfile)

renWin = vtkRenderWindow()
renWin.SetWindowName("%s"%vtkfile)
renWin.SetPolygonSmoothing(1)
#renWin.SetAAFrames(2)
示例#7
0
def chgcarBondAnalysis(chgcarfile,
                       bondLengths,
                       normalize=False,
                       verbose=False):

    BLs = bondLengths
    nBLs = len(BLs)

    #Parse CHGCAR
    chgcar = open(chgcarfile, "r").readlines()
    (v1, v2, v3, atypes, axs, ays, azs,
     header), gridSize, chg = chgcarIO.read(chgcar)
    basis = asarray([v1, v2, v3])
    lengths = array([v1[0], v2[1], v3[2]])
    atoms = array(zip(axs, ays, azs))

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

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

    a = chg.shape
    AvgChg = sum([sum([sum(line) for line in plane])
                  for plane in chg]) / a[0] / a[1] / a[2]
    if verbose:
        print "Average CHG value:", AvgChg

    #Evaluate the CHG between each nieghbor pair
    avgchgline, xchglines, ychglines, halfNeighbors = fieldNeighbors1D(
        atoms, atypes, basis, chg, gridSize, halfNeighbors)

    #Cutoff neighbors that fall below the thresh-hold
    Ninterp = len(avgchgline)
    avgIBL = zeros([nBLs, Ninterp])  #avg line inside the bond length
    avgOBL = zeros([nBLs, Ninterp])  #avg line outside the bond length
    nibl = zeros(nBLs)
    nobl = zeros(nBLs)

    cnt = 0
    for a, jNeighbors in enumerate(halfNeighbors):
        atoma = atoms[a]
        for b, jNeighb in enumerate(jNeighbors):
            atomb = atoms[jNeighb]
            d = dist_periodic(atoma, atomb, lengths)
            vals = ychglines[a][b]
            xx = xchglines[a][b]
            for j, bl in enumerate(BLs):
                if normalize:
                    avals = array(vals) / AvgChg
                else:
                    avals = array(vals)
                if d < bl:
                    nibl[j] += 2
                    avgIBL[j] += avals
                    avgIBL[j] += avals[::-1]
                else:
                    cnt += 1
                    nobl[j] += 2
                    avgOBL[j] += avals
                    avgOBL[j] += avals[::-1]
    for i in range(nBLs):
        if nibl[i] == 0:
            nibl[i] = 1
        if nobl[i] == 0:
            nobl[i] = 1
    avgOBL = [avgOBL[i] / nobl[i] for i in range(nBLs)]
    avgIBL = [avgIBL[i] / nibl[i] for i in range(nBLs)]
    return avgOBL, nobl, avgIBL, nibl
示例#8
0
    if clean==True:
        chgdata=chgdata.ravel()
        def clearoutlier(i,a): return 1.0 if i>a else i/a
        avgval=scipy.sum(chgdata)/Tot_pnts
        vclearout=vectorize(clearoutlier)
        chgdata=vclearout(chgdata,avgval)
        #chgdata=array([i/avgval for i in chgdata])
        chgdata.shape=gridsz
    #chgdata=chgdata.ravel()
    for i in range(gridsz[0]):
         for j in range(gridsz[1]):
            vtkfile.write(" ".join(map(lambda x:str(x),chgdata[i][j]))+"\n")
"""

def usage():
    print "Usage: %s <input chgcar> <optional:output vtk filename>"%sys.argv[0].split("/")[-1]

if len(sys.argv)<2:
    usage()
    exit(0)
    
chgfname=sys.argv[1]
if len(sys.argv)==3:
    vtkfname=sys.argv[2]
else:
    vtkfname=chgfname+".vtk"

poscardata,chgdata=chgcarIO.read(open(chgfname,"r").readlines())
chgcarIO.writeVTK(vtkfname,poscardata,chgdata,clean=True)
示例#9
0
    chgcarfiles=sys.argv[1].split(",")
    bondLengths=map(float,sys.argv[2].split(","))
    normalize=False
    if len(sys.argv)>3:
        if sys.argv[3][0] in ["n","N"]:
            normalize=True
    verbose=True

    Ninterps=[50,50]
    if len(sys.argv)>4:
        Ninterps=map(int,sys.argv[5].split(","))

    for chgcarfile in chgcarfiles:

        avgGrids,grids,bondCounts=chgcarBondAnalysis(chgcarfile,bondLengths,normalize,verbose,Ninterps=Ninterps,loc="center")
        chgcar=open(chgcarfile,"r").readlines()
        poscardata,gridSize,chg = chgcarIO.read(chgcar)
        
        """
        for avgGrid,bondCount,cutoff in zip(avgGrids,bondCounts,bondLengths):
            #vtkfname=chgcarfile+"_cut%2.2f_NBond%d.vtk"%(cutoff,bondCount)
            #chgcar.writeVTK(vtkfname,poscardata,avgGrid.shape,avgGrid)
            pl.imshow(avgGrid[0])
            pl.show()
        """
        for i,grid in enumerate(grids):
            pl.savetxt("grid%d_%s.data"%(i,chgcarfile),grid)
            pl.imshow(grid)
            pl.show()
示例#10
0
        def clearoutlier(i,a): return 1.0 if i>a else i/a
        avgval=scipy.sum(chgdata)/Tot_pnts
        vclearout=vectorize(clearoutlier)
        chgdata=vclearout(chgdata,avgval)
        #chgdata=array([i/avgval for i in chgdata])
        chgdata.shape=gridsz
    #chgdata=chgdata.ravel()
    for i in range(gridsz[0]):
         for j in range(gridsz[1]):
            vtkfile.write(" ".join(map(lambda x:str(x),chgdata[i][j]))+"\n")
"""


def usage():
    print "Usage: %s <input chgcar> <optional:output vtk filename>" % sys.argv[
        0].split("/")[-1]


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

chgfname = sys.argv[1]
if len(sys.argv) == 3:
    vtkfname = sys.argv[2]
else:
    vtkfname = chgfname + ".vtk"

poscardata, chgdata = chgcarIO.read(open(chgfname, "r").readlines())
chgcarIO.writeVTK(vtkfname, poscardata, chgdata, clean=True)
示例#11
0
def chgcarBondAnalysis(chgcarfile,bondLengths,normalize=False,verbose=False):

    BLs=bondLengths
    nBLs=len(BLs)

    #Parse CHGCAR
    chgcar=open(chgcarfile,"r").readlines()
    (v1,v2,v3,atypes,axs,ays,azs,header),gridSize,chg = chgcarIO.read(chgcar)
    basis=asarray([v1,v2,v3])
    lengths=array([v1[0],v2[1],v3[2]])
    atoms=array(zip(axs,ays,azs))

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

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

    a=chg.shape
    AvgChg=sum([sum([sum(line) for line in plane]) for plane in chg])/a[0]/a[1]/a[2]
    if verbose:
        print "Average CHG value:",AvgChg

    #Evaluate the CHG between each nieghbor pair
    avgchgline,xchglines,ychglines,halfNeighbors=fieldNeighbors1D(atoms,atypes,basis,chg,gridSize,halfNeighbors)

    #Cutoff neighbors that fall below the thresh-hold
    Ninterp=len(avgchgline)
    avgIBL=zeros([nBLs,Ninterp]) #avg line inside the bond length
    avgOBL=zeros([nBLs,Ninterp]) #avg line outside the bond length
    nibl=zeros(nBLs)
    nobl=zeros(nBLs)

    cnt=0
    for a,jNeighbors in enumerate(halfNeighbors):
        atoma=atoms[a]
        for b,jNeighb in enumerate(jNeighbors):
            atomb=atoms[jNeighb]
            d=dist_periodic(atoma,atomb,lengths)
            vals=ychglines[a][b]
            xx=xchglines[a][b]
            for j,bl in enumerate(BLs):
                if normalize:
                    avals=array(vals)/AvgChg
                else:
                    avals=array(vals)
                if d<bl:
                    nibl[j]+=2
                    avgIBL[j]+=avals
                    avgIBL[j]+=avals[::-1]
                else:
                    cnt+=1
                    nobl[j]+=2
                    avgOBL[j]+=avals
                    avgOBL[j]+=avals[::-1]
    for i in range(nBLs):
        if nibl[i]==0:
            nibl[i]=1
        if nobl[i]==0:
            nobl[i]=1
    avgOBL=[avgOBL[i]/nobl[i] for i in range(nBLs)]
    avgIBL=[avgIBL[i]/nibl[i] for i in range(nBLs)]
    return avgOBL,nobl,avgIBL,nibl
示例#12
0
    usage()
    exit(0)

rVals = None
if len(sys.argv) == 3:
    chgcarfile = sys.argv[1]
    rVals = [float(sys.argv[2])]
if len(sys.argv) == 5:
    chgcarfile = sys.argv[1]
    rStart = float(sys.argv[2])
    rStop = float(sys.argv[3])
    rSteps = int(sys.argv[4])
    rVals = [(rStop - rStart) * i / rSteps + rStart for i in range(rSteps)]

chgcar = open(chgcarfile, "r").readlines()
pcar, chg = chgcarIO.read(chgcar)
(basis, atypes, atoms, head) = pcar

#R space distance between grid points
delR = sum([np.linalg.norm(basis[i]) / chg.shape[i] for i in range(3)]) / 3.0

bounds = chg.shape
xGrids, yGrids, zGrids = [range(i) for i in bounds]
gridCoords = [i for i in itertools.product(xGrids, yGrids, zGrids)]
for rCut in rVals:
    chgs = list()
    coordShifts = sphereCoords(delR, rCut)
    N = coordShifts.shape[0]
    a = 0
    for gc in gridCoords:
        x, y, z = np.split(gen2BCoords(gc, coordShifts, bounds), 3, axis=1)
示例#13
0
import sys
import pylab as pl
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")
示例#14
0
    usage()
    exit(0)

rVals=None
if len(sys.argv)==3:
    chgcarfile = sys.argv[1]
    rVals = [float(sys.argv[2])]
if len(sys.argv)==5:
    chgcarfile = sys.argv[1]
    rStart = float(sys.argv[2])
    rStop = float(sys.argv[3])
    rSteps = int(sys.argv[4])
    rVals = [(rStop-rStart)*i/rSteps+rStart for i in range(rSteps)]

chgcar=open(chgcarfile,"r").readlines()
pcar,chg = chgcarIO.read(chgcar)
(basis,atypes,atoms,head)=pcar

#R space distance between grid points
delR = sum([np.linalg.norm(basis[i])/chg.shape[i] for i in range(3)])/3.0

bounds=chg.shape
xGrids,yGrids,zGrids=[range(i) for i in bounds]
gridCoords=[i for i in itertools.product(xGrids,yGrids,zGrids)]
for rCut in rVals:
    chgs=list()
    coordShifts=sphereCoords(delR,rCut)
    N=coordShifts.shape[0]
    a=0
    for gc in gridCoords:
        x,y,z=np.split(gen2BCoords(gc,coordShifts,bounds),3,axis=1)