Note : To use materials project data frequently, you may need to save their api key into file. Run function below and it saves key to a file and every function will autoload it.
periodic_table()
def field(x,y,z):
u, v, w = y, -x , z
norm = 5*(u*u + v*v + w*w)**(1/2)
if norm == 0:
return (x,y,z,0.01,0.01,0.01)
return (x,y,z, u/norm, v/norm, w/norm)
X,Y,Z = np.mgrid[0:1:10j,0:1:10j,0:1:3j]
vs = np.concatenate([X.ravel(),Y.ravel(),Z.ravel()]).reshape((3,-1)).T
ef = np.array([field(*v) for v in vs]).T
C = np.abs(ef[3:,:].T)
C = C/np.max(C)
ax1, ax2 = sp.get_axes(ncols=2,figsize=(6,3),axes_3d=[0,1])
bz = get_bz([[1,0,0],[0,1,0],[0,0,1]],primitive=True)
splot_bz(bz,ax=ax1,vname='x',fill=False,color=(0.8,0.7,0.2,0.7))
splot_bz(bz,ax=ax2,vname='x',fill=False,color=(0.8,0.7,0.2,0.7))
fancy_quiver3d(*ef,C = C,ax=ax1,L=0.01,mutation_scale=7,capstyle='butt',arrowstyle='wedge').set_box_aspect((1,1,1))
ax1.set_axis_off()
ax1.set_title('Fancy Quiver 3D')
# Repeat for each body line and two head lines
C = np.concatenate([C,np.repeat(C, 2, axis=0)])
q = ax2.quiver(*ef,lw=1,colors=C)
ax2.set_title('Default Quiver 3D')
ax2.set_box_aspect((1,1,1))
ax2.set_axis_off()
mp = InvokeMaterialsProject()
out = mp.request('AlAs',max_sites=4,min_sites=2)
print("material_id: ",out[1].mp_id)
print("spacegroup symbol: ",out[1].symbol)
write_poscar(out[1].export_poscar())
read_ticks('kpt.txt')
In example below, the overall value of n = 5
is skipped and 4th entry in the point is used instead. In later example, a 'skipk' label removes high symmetry point index.
get_kpath({'_L':[0.5,0.5,0.5],'G':[0,0,0]},n=9,ibzkpt='IBZKPT')
get_kpath({'M':[0.375,0.375,0.5,21],'skip': [0,0,0]},{'G':[0.5,0.25,0.5],'M':[0,0,0]},{'L':[0.25,0.25,0.25],'K':[0,0,0]},n=11,outfile='kpt.txt')
Automatically generated using PivotPy with HSK-INDS = [0, 29, -1], LABELS = ['M', 'G', 'M|L', 'K'], SEG-INDS = [21, 29]
HSK-INDS = [0, 29, -1]
should be [0,21,29,-1]
but skip
label removed it. Also after 21, it may have 32 as n=11, but distance smaller than 1 resulted in only 8 points there. This is pretty useful if you don't need to rescale kpoint axis later on based on distance.
str2kpath('0 0 0 G 2\n 1 1 1 X\n1/2 1/2 1/2 skip',n=4)
_get_basis([[ 4.00771850e+00, 0.00000000e+00, -0.00000000e+00],
[ 2.00385925e+00, 3.47078603e+00, 5.06700000e-13],
[ 2.00385925e+00, 1.15692868e+00, 3.27228845e+00]]).inverted
KPOINTS Mesh for Fermi Surface Calculations
- The command
get_kmesh
generates a uniform grid in first (primitive) Brillouin zone. - You can generate cartesian grid as well which is easier in output plotting.
mp = InvokeMaterialsProject()
out = mp.request('GaAs',max_sites=2)
get_kmesh(out[0].export_poscar(),3,shift= -0.5,cartesian = True)
import numpy as np
print("Interier Angle:",_rad_angle([0,0.1,0],[0,0.5,1]))
print("Angle with x-axis:",_tan_inv(1,0))
pts = np.array([[1,0,3],[0,0,0],[0,1,2]])
inds = order(pts)
pts[inds]
import numpy as np
bbya = 1.2
cbya = 0.8
ofco = [[1,bbya,0],[-1,bbya,0],[0,0,cbya]]
bco = [[1,bbya,cbya],[-1,bbya,cbya],[-1,-bbya,cbya]]
fco = [[1,0,cbya],[1,bbya,0],[0,bbya,cbya]]
bcc = [[1,1,1],[-1,1,1],[-1,-1,1]]
cube = [[1,0,0],[0,1,0],[0,0,1]]
hexa = [[1,0,0],[0.5,np.sqrt(3)/2,0],[0,0,1]]
ctg = [[1,1,cbya],[1,-1,cbya],[-1,-1,cbya]]
tgl = [[0.81915,-0.472937,0.94923],[0,0.94587,0.94923],[-0.81915,-0.472937,0.94923]]
fcc =[[0.0000000000000000, 0.5020149905223673, 0.5020149905223673],
[0.5020149905223673, 0.0000000000000000, 0.5020149905223673],
[0.5020149905223673, 0.5020149905223673, 0.0000000000000000]]
basis,normals,vertices,faces,specials = get_bz(fcc,digits=4)
print(basis)
for k,v in zip(specials.coords[:10],specials.kpoints[:10]):
print(v,'-->',k)
import pivotpy.splots as sp
lat = hexa
bz = get_bz(lat,primitive=False,loop=True)
axs = sp.get_axes(ncols=4,figsize=(9,2))
ax2d = splot_bz(bz,plane='xy',ax=axs[0],vectors=True,color=(0.7,0,0.5))
ax3d = splot_bz(bz,ax=axs[1],color=(108/255,204/255,215/255,0),vectors=True,light_from=(10,10,30),alpha=0.5,colormap=None)
prim_bz = get_bz(lat,primitive=True)
ax3d_ = splot_bz(prim_bz,ax=axs[2],color=(212/255,175/255,55/255,0),vectors=True)
_ax3d = splot_bz(get_bz(prim_bz.basis,primitive=True),ax=axs[3],color=(212/255,175/255,55/255,0),vectors=True,vname='a',colormap='turbo_r',light_from=(0,1,1))
ps = bz.specials.coords[bz.specials.near[4]][[0,1,8,2,5,4]]
ax3d.scatter(ps[:,0],ps[:,1],ps[:,2],c='r',s=20)
ax2d.scatter(ps[:,0],ps[:,1],c='r',s=20)
ax3d.set_axis_off()
ax3d.set_title('Regular BZ')
ax3d_.set_axis_off()
ax3d_.set_title('Primitive BZ')
ax2d.set_axis_off()
_ax3d.set_title('Real lattice')
_ax3d.set_axis_off()
ax2d.set_title('XY Projection of Regular BZ')
sp.plt2html()
- Below is a BZ plot using command
iplot_bz()
. Same color points lie on a sphere, with radius decreasing as red to blue and gamma point in gold color. These color help distinguishing points but the points not always be equivalent, for example in FCC, there are two points on mid of edges connecting square-hexagon and hexagon-hexagon at equal distance from center but not the same points.Note:iplot_bz
includes special points only if vname =b
, i.e. in recirpocal space.
import pivotpy as pp
fig = iplot_bz(get_bz([[1,0,1],[1,1,0],[0,1,1]]),alpha=1)
pp.iplot2html(fig,modebar=False)
x = to_R3(_get_basis(hexa).inverted,[[1,1,1],[0.333,0.333,0.5]])
y = to_basis(_get_basis(hexa).inverted,x)
print(x,y)
import pivotpy as pp, numpy as np
fig = iplot_bz(get_bz(hexa))
prim_bz = get_bz(hexa,primitive=True)
iplot_bz(get_bz(prim_bz.basis,primitive=True),vname='a',fig=fig,color="rgba(200,220,10,0.4)")
pp.iplot2html(fig,modebar=False)
Example: Showing Energy as Color on BZ
In below figure, left side of colorbar is tricontourf
and right side is scatter
plot with color based on energy value of VBM.
For a more easier way of doing this, see pivotpy.SpinDataFrame
and See Example
import matplotlib.pyplot as plt , pivotpy as pp
import matplotlib.tri as tri
axs = pp.get_axes(ncols=5,figsize=(9,2.3),widths=[5,5,0.5,5,5])
evr = pp.Vasprun('../graphene_example/ISPIN_1/dos/vasprun.xml').data
kpoints = np.concatenate([evr.kpoints, -evr.kpoints]) # negative side
bz1 = get_bz(evr. poscar.basis,primitive=True)
bz2 = get_bz(evr.poscar.basis,primitive=False)
out1 = kpoints2bz(bz1,kpoints,primitive=True, shift=0.5)
out2 = kpoints2bz(bz2,kpoints,primitive=False)
splot_bz(bz1,plane='xy',ax = axs[0],color=(1,1,1,0)).set_axis_off()
splot_bz(bz2,plane='xy',ax = axs[1]).set_axis_off()
splot_bz(bz1,plane='xy',ax = axs[3]).set_axis_off()
splot_bz(bz2,plane='xy',ax = axs[4]).set_axis_off()
# Energy as color on BZ.
en = evr.bands.evals[:,8].ravel()
en = np.concatenate([en,en])
s_en = (en-np.min(en))/(np.max(en)-np.min(en)) # bring to range [0,1] for colors
c = plt.cm.get_cmap('plasma')(s_en)
labels = [str(l) + ' eV' for l in np.round(np.min(en)+(np.max(en)-np.min(en))*np.array([1/6,3/5,5/6]),2)]
tri1 = tri.Triangulation(out1.T[0], out1.T[1])
tri2 = tri.Triangulation(out2.T[0], out2.T[1])
axs[0].tricontourf(tri1, en, levels=np.linspace(-2.6, 3.4, 8), cmap='plasma')
axs[1].tricontour(tri2, en, levels=np.linspace(-2.6, 3.4, 8), cmap='plasma',linewidths=[0.8])
axs[3].scatter(out1[:,0],out1[:,1],s=4,c=c)
axs[4].scatter(out2[:,0],out2[:,1],s=4,c=c)
axs[2].add_colorbar(cax=axs[2],cmap_or_clist='plasma', ticklabels=labels,vertical=True)
import pivotpy as pp
fig=iplot_lat(evr.poscar,sizes=10,line_width=4,fill=False)
pp.iplot2html(fig,modebar=False)
plt.style.use('ggplot')
axs = pp.get_axes((6,6),ncols=2,axes_3d=[0,])
splot_lat(evr.poscar,sizes=40,plane=None,fill=True,tol=0.2,alpha=0.4,light_from=(1,-0.1,0),vectors=False,ax=axs[0],edge_color=(0.5,0.5,0,0.4), eqv_sites=True)
splot_lat(evr.poscar,sizes=40,plane='xy',fill=True,tol=0.1,alpha=1,light_from=(1,-0.1,0),vectors=False,ax=axs[1],colors=['r'],eqv_sites=True).set_axis_on()
axs[0].view_init(70,75)
write_poscar(evr.poscar)
print("===================================================")
sd = get_selective_dynamics(evr.poscar,a=[(0,0.5)],c= [(0,0.5)])
write_poscar(evr.poscar,selective_dynamics=sd)
import numpy as np
import pivotpy.parser as vp
pscr = export_poscar('POSCAR')
ax = splot_lat(pscr,plane='xy',colors='r',sizes=100,line_width=5)
scaled = scale_poscar(pscr, scale=[3,3,3])
splot_lat(scaled, ax=ax,plane='xy',colors='b',bond_length=0.1,tol=1e-5,line_width=2)
new_scaled = scale_poscar(scaled, scale=[1/3,1/3,1/3],tol=1e-3)
splot_lat(new_scaled,ax=ax,plane='xy',colormap='viridis_r',sizes=15,line_width=0.5)
trans = transform_poscar(scaled, get_transform_matrix(scaled, -scaled.basis))
splot_lat(trans,ax=ax,plane='xy',colormap='viridis_r',sizes=15,colors='g',line_width=0.5)