Index 
  Example 
  StaticPlots 
  InteractivePlots 
  SpinProjectedSurfaces● 
  StructureIO 
  Widgets 
  MainAPI 

class SpinDataFrame[source]

SpinDataFrame(*args, path=None, bands=[0], elements=[[0]], orbs=[[0]], scale_data=False, elim=None, skipk=None, data=None, **kwargs) :: DataFrame

Spin data from vasprun.xml is converted to a dataframe.

  • Parameters:

    • path: path to vasprun.xml or auto picks in current directory.
    • bands: list of band indices [zero based here], In output data frame you will see corresponding band number based on full data.
    • elements: list of elements to plot. inner list contains ions indices. Can leave empty to discard projection data.
    • orbs: list of orbitals to plot. inner list contains orbitals indices. Can leave empty to discard projection data
    • scale_data: if True, spin data is scaled to -1 to 1.
    • skipk: if not None, auto skipped unnecessary k-points.
    • elim: if not None, filtered out unnecessary bands.
    • data: if not None, data is loaded from given data/pickle/json/dict and validated. Many other parameters are ignored when data is given.
  • Returns:

    • SpinDataFrame: dataframe with colums as k-points, eigenvalues[with fermi energy subtracted], spin components projected over selected ions and orbtials.
  • Methods:

    • sliced: Slice data in a plane orthogonal to given column at given value.
    • masked: Mask data over a constant value in a given column. Useful for plotting fermi level/surface.
    • splot: plot data in a 2D plot.
    • splot3d: plot data in a 3D plot.
    • join/append/concat/+/+=: Append another SpinDataFrame to this one with same columns and copy metadata.
    • send_metadata: Copy metadata from this to another SpinDataFrame, some methods may not carry over metadata, useful in that case.
    • get_data: Return data as collection of numpy arrays with kpoints already sent to BZ. Use .to_json() to export to json for plotting in other libraries/languages like Mathematica.

      All other methods are inherited from pd.DataFrame. If you apply some method that do not pass metadat, then use send_metadata to copy metadata to traget SpinDataFrame.

Examples

Data is not complete though :-)

df = SpinDataFrame(path = r'E:\Research\graphene_example\ISPIN_2\dos\sigm0_01\vasprun.xml',
                   bands=[3,4],elements=[[0],[1]], orbs= [(0,1),(1,2,3)],scale_data=True)
df
 Found ISPIN = 2, output data got attributes spins.<u,d> instead of spins.<s,x,y,z>
kx ky kz band eu ed su_0 sd_0 su_1 sd_1
0 0.024390 0.000000 0.0 4 -2.8008 -2.8008 0.748786 0.748786 1.000000 1.000000
1 0.048780 0.000000 0.0 4 -2.8918 -2.8918 0.747573 0.747573 0.997087 0.997087
2 0.073171 0.000000 0.0 4 -3.0364 -3.0364 0.744660 0.744660 0.992961 0.992961
3 0.097561 0.000000 0.0 4 -3.2256 -3.2256 0.740777 0.740777 0.987864 0.987864
4 0.121951 0.000000 0.0 4 -3.4473 -3.4473 0.737136 0.737136 0.982767 0.982767
... ... ... ... ... ... ... ... ... ... ...
1675 -0.121951 0.487805 0.0 5 2.6564 2.6564 0.000000 0.000000 0.605340 0.605340
1676 -0.097561 0.487805 0.0 5 2.4606 2.4606 0.000000 0.000000 0.587136 0.587136
1677 -0.073171 0.487805 0.0 5 2.2749 2.2749 0.000000 0.000000 0.570874 0.570874
1678 -0.048780 0.487805 0.0 5 2.1127 2.1127 0.000000 0.000000 0.557282 0.557282
1679 -0.024390 0.487805 0.0 5 1.9870 1.9870 0.000000 0.000000 0.547573 0.547573

1680 rows × 10 columns

df_m = df.copy()
df_m[['kx','ky','kz']] = -df[['kx','ky','kz']]
df1 = df.join(df_m)
df2 = df1.masked('eu',2,0.05,n=100,band=5)
df2
kx ky kz band eu ed su_0 sd_0 su_1 sd_1
5 -0.487805 -0.438532 0.0 5.0 1.964018 1.964018 0.0 0.0 0.760659 0.760659
6 -0.487805 -0.428677 0.0 5.0 2.008382 2.008382 0.0 0.0 0.768423 0.768423
41 -0.487805 -0.083764 0.0 5.0 2.009391 2.009391 0.0 0.0 0.768616 0.768616
42 -0.487805 -0.073910 0.0 5.0 1.965027 1.965027 0.0 0.0 0.760853 0.760853
51 -0.487805 0.014782 0.0 5.0 1.954736 1.954736 0.0 0.0 0.744481 0.744481
... ... ... ... ... ... ... ... ... ... ...
9948 0.487805 -0.014782 0.0 5.0 1.954736 1.954736 0.0 0.0 0.744481 0.744481
9957 0.487805 0.073910 0.0 5.0 1.965027 1.965027 0.0 0.0 0.760853 0.760853
9958 0.487805 0.083764 0.0 5.0 2.009391 2.009391 0.0 0.0 0.768616 0.768616
9993 0.487805 0.428677 0.0 5.0 2.008382 2.008382 0.0 0.0 0.768423 0.768423
9994 0.487805 0.438532 0.0 5.0 1.964018 1.964018 0.0 0.0 0.760659 0.760659

258 rows × 10 columns

ax1,ax2 = api.get_axes((3,3),ncols=2,widths=[20,1],hspace=0.1,wspace=0.1)

df2.poscar.set_bz(primitive = False)
df2.splot('kx','ky','eu',s=5,ax=ax1,color='k')
df2.splot('kx','ky','eu','su_1',arrows=['','su_1','su_1'],every=6,quiver_kws= dict(cmap='brg',scale=20),ax=ax1)
df2.colorbar(ax2)
df2.poscar.splot_bz(plane='xy',ax=ax1)
ax1.set_title('Band 5 at $E = 2 \pm 0.05$ eV')
ax2.yaxis.set_label_position("right")
ax2.set_ylabel('$S_\\uparrow(C_1-p)$')
Text(0, 0.5, '$S_\\uparrow(C_1-p)$')
2022-09-02T11:41:34.976178 image/svg+xml Matplotlib v3.3.3, https://matplotlib.org/
df1['kz'] = 0
ax = df1.splot3d('kx','ky','eu','su_1',s=10,cmap='inferno')
df1.colorbar()
df3 = df1[df1['band'] == 5]
ax1 = df3.splot3d('kx','ky','kz',arrows=['','','su_1','eu'],norm=0.1,every=2,quiver_kws= dict(mutation_scale=5,arrowstyle='-|>',cmap='brg',zorder=3))
df3.poscar.splot_bz(ax=ax1).set_axis_off()
df3.colorbar()
ax.set(xlabel='$k_x $',ylabel='$k_y$',zlabel='$E_\\uparrow$')
ax1.view_init(elev=60,azim=45)
ax.set_title('$E_\\uparrow$ of Band 4,5 colored by $S_\\uparrow (C_1-p)$')
ax1.set_title('$S_\\uparrow (C_1-p)$ colored by $E_\\uparrow$ of Band 5')
Text(0.5, 0.92, '$S_\\uparrow (C_1-p)$ colored by $E_\\uparrow$ of Band 5')
2022-09-02T11:41:40.367419 image/svg+xml Matplotlib v3.3.3, https://matplotlib.org/
2022-09-02T11:41:41.747432 image/svg+xml Matplotlib v3.3.3, https://matplotlib.org/

Plotting with any Library/Langauge

  • You can plot using methods of your choices from your favorite libraries, to collect data for that purpose, see example below.
  • You can use df.get_data().to_json('file.json') to save current data and open that in any other language of your choice.
ax3d = api.get_axes(axes_3d=True)
data = df2.get_data().band_5
KPTS = np.array([data.kx,data.ky,data.kz]).T
KPTS[:,2] = 0
ax3d.scatter(data.kx,data.ky,data.kz,c = data.eu,s=2,cmap='inferno')
df2.poscar.splot_bz(ax=ax3d,fill=False)

UVW = np.array([data.su_0, data.sd_1, data.su_1]).T
api.fancy_quiver3d(*KPTS[::8].T,*UVW[::8].T/5,C = np.abs(UVW)[::8]/UVW.max(),arrowstyle='-|>',ax=ax3d)
ax3d.set_axis_off()
ax3d.view_init(elev=60,azim=90)
2022-09-02T11:41:42.515095 image/svg+xml Matplotlib v3.3.3, https://matplotlib.org/
import plotly.graph_objects as go
fig = go.Figure()
fig.add_scatter3d(x = KPTS[:,0],y = KPTS[:,1], z = KPTS[:,2],marker =dict(color= np.abs(UVW)/UVW.max(),size=2),mode='markers')
df2.poscar.iplot_bz(fig=fig)
fig.add_cone(x = KPTS[::8,0],y = KPTS[::8,1], z = KPTS[::8,2],u = UVW[::8,0],v = UVW[::8,1], w = UVW[::8,2],sizemode='absolute',sizeref=50,colorscale='magma',showscale=False)
api.iplot2html(fig, modebar= False)

Under Development

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.tri as mtri


# Creating dataset
data = df1.get_data().band_4
x = data.kx
y = data.ky
z = data.eu
tri = mtri.Triangulation(x, y)

new_x = tri.x[tri.triangles].mean(axis=1)
new_y = tri.y[tri.triangles].mean(axis=1)

new_color = griddata((x,y),data.su_1,(new_x,new_y),method='linear')
new_color = np.abs((new_color - new_color.min())/np.ptp(new_color))

verts = np.array([tri.x[tri.triangles],tri.y[tri.triangles],z[tri.triangles]]).transpose([1,2,0])
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
import pivotpy as pp

col = Poly3DCollection(verts,color=plt.get_cmap('brg')(new_color))
ax = pp.get_axes(axes_3d=True)
ax.add_collection3d(col)
ax.autoscale()
#df1.poscar.splot_bz(ax=ax,fill=False)
ax.set(zlim=(-6,0),xlim=(-0.27,0.27),ylim=(-0.24,0.24),
       zlabel='$E_\\uparrow$',xlabel='$k_x$',ylabel='$k_y$',
       title='Color by $S_\\uparrow$ over $E_\\uparrow$ surface')
ax.view_init(elev=45,azim=45)
cax = ax.get_figure().add_axes([0.9,0.1,0.03,0.8])
pp.add_colorbar(ax,'brg',cax = cax, ticks=np.linspace(data.su_1.min(),data.su_1.max(),5))
<matplotlib.axes._axes.Axes at 0x166d9480148>
2022-09-02T11:41:46.215195 image/svg+xml Matplotlib v3.3.3, https://matplotlib.org/
df1.get_data().to_json('../FermiData.json')