Quickstart

Binder

[1]:
import numpy as np
import matplotlib.pyplot as plt

import ipyvasp as ipv

Transform POSCAR

Let’s create some dummy POSCAR.

[2]:
poscar = ipv.POSCAR.new(
    [[0.5, 0.5, 0.0], [0.0, 0.5, 0.5], [0.5, 0.0, 0.5]],
    {"Ga": [[0.0, 0.0, 0.0]],"As": [[0.25, 0.25, 0.25]]},

    scale = 5
)

poscar.write("POSCAR",overwrite=True) # need it later

site_kws = dict(alpha=1)
ax1, ax2, ax3 = ipv.get_axes((8,3),ncols=3, axes_3d=[0,1,2])

poscar.splot_lattice( ax = ax1, fill = False,label='original',
    site_kws=site_kws)

_ = poscar.transform(lambda a,b,c: (b+c-a, a+c-b, a+b-c)).transpose([1,2,0]) # bring a1 to x
print(poscar.last.data.metadata.TM)
poscar.last.splot_lattice( # .last points to last created POSCAR in transform
    ax=ax2, fill = False, color='red', label='transformed',
    site_kws=site_kws
)
poscar.last.splot_plane([1,1,0],1/2,ax=ax2)

poscar.transform(lambda a,b,c: (a-c,b-c,a+b+c)
).set_zdir([0,0,1]).splot_lattice(ax=ax3,color='red')

print(poscar.last.data.metadata.TM)
ax1.view_init(azim=-25, elev=15)
ax2.view_init(azim=-35, elev=15)
[[0.  0.5 0.5]
 [0.5 0.  0.5]
 [0.5 0.5 0. ]]
[[ 0.66666667 -0.33333333  0.33333333]
 [-0.33333333  0.66666667  0.33333333]
 [-0.33333333 -0.33333333  0.33333333]]
<Figure size 1152x432 with 0 Axes>
[3]:
poscar.splot_bz(fill = True,color='skyblue', vectors=None,lw=0.1).set_axis_off()
ax = poscar.splot_kpath([(0,0,0), (1/4,1/2,-1/4), (0.5,0.5,0), (0,0,0), (0,0.5,0)],
    labels = ['Γ', 'K', 'X', 'Γ', 'L'], fmt_label=lambda lab: lab+'\n')
ax.view_init(azim=55, elev=25)
<Figure size 489.6x489.6 with 0 Axes>
[4]:
fig = poscar.iplot_bz(color='blue')
ipv.iplot2html(fig)
[4]:

K-Path

We can interplate kpath based on current POSCAR, it gives correct distance between points.

[5]:
poscar.get_kpath([
    (0,0,0,'Γ'),
    (1/4,1/2,-1/4,'K'),
    (0.5,0.5,0,'X'),
    (0,0,0,'Γ'),
    (0,0.5,0,'L')
    ], n=8)
Automatically generated using ipyvasp for HSK-PATH 0:Γ, 4:K, 5:X, 9:Γ, 12:L
        13
Reciprocal Lattice
    0.0000000000    0.0000000000    0.0000000000    0.076923
    0.0625000000    0.1250000000   -0.0625000000    0.076923
    0.1250000000    0.2500000000   -0.1250000000    0.076923
    0.1875000000    0.3750000000   -0.1875000000    0.076923
    0.2500000000    0.5000000000   -0.2500000000    0.076923
    0.5000000000    0.5000000000    0.0000000000    0.076923
    0.3750000000    0.3750000000    0.0000000000    0.076923
    0.2500000000    0.2500000000    0.0000000000    0.076923
    0.1250000000    0.1250000000    0.0000000000    0.076923
    0.0000000000    0.0000000000    0.0000000000    0.076923
    0.0000000000    0.1666666667    0.0000000000    0.076923
    0.0000000000    0.3333333333    0.0000000000    0.076923
    0.0000000000    0.5000000000    0.0000000000    0.076923
[6]:
poscar.get_kmesh(2,2,2, weight=0)
Generated uniform mesh using ipyvasp, GRID-SHAPE = [2,2,2]
        8
Reciprocal
    0.0000000000    0.0000000000    0.0000000000    0.000000
    1.0000000000    0.0000000000    0.0000000000    0.000000
    0.0000000000    1.0000000000    0.0000000000    0.000000
    1.0000000000    1.0000000000    0.0000000000    0.000000
    0.0000000000    0.0000000000    1.0000000000    0.000000
    1.0000000000    0.0000000000    1.0000000000    0.000000
    0.0000000000    1.0000000000    1.0000000000    0.000000
    1.0000000000    1.0000000000    1.0000000000    0.000000
[7]:
view = poscar.view_weas(colors={'Ga':'red','As':'blue'})
view
[7]:

If you are not seeing interactive widget above, don’t worry! We’ve got you covered with a screenshot below:

[8]:
view.download_image('weas.png')

GaAs

Live View of POSCAR Operations

op.png

Batch analysis using Files class.

[9]:
files = ipv.Files('.')
files
[9]:
Files(
  PosixPath('POSCAR'),
  PosixPath('quickstart.ipynb'),
  PosixPath('weas.png')
) 3 items
[10]:
files.summarize(lambda path: {'end': path.parts[-1]})
[10]:
end FILE
0 POSCAR POSCAR
1 quickstart.ipynb quickstart.ipynb
2 weas.png weas.png
[11]:
files.map(lambda p: p.suffix,to_df=True)
[11]:
0 1
0 POSCAR
1 quickstart.ipynb .ipynb
2 weas.png .png
[12]:
files.interactive(lambda file: print(file))
[12]:
[13]:
files.filtered('py')
[13]:
Files(
  PosixPath('quickstart.ipynb')
) 1 items

Example: View Lattice and BZ side by side

[14]:
import plotly.graph_objects as go
import ipyvasp as ipv
fs = ipv.Files('.','POSCAR')

@fs.interact(fig1 = go.FigureWidget(), fig2 = go.FigureWidget(),
    app_layout={"left_sidebar": ('file', 'fig2'), 'center':('fig1',),'pane_widths':[2,3,0]})
def view(file, fig1, fig2):
    pos = ipv.POSCAR(file)
    ipv.iplot2widget(pos.iplot_bz(), fig_widget=fig2)
    ipv.iplot2widget(pos.iplot_lattice(), fig_widget=fig1)
image.png