A description of your project
Project description
PivotPy
<style>a{text-decoration: none !important;color:lightkblue;font-weight:bold;} a:focus,a:active,a:hover{color:hotpink !important;}</style>A Python Processing Tool for Vasp Input/Output. A CLI is available in Powershell, see Vasp2Visual.
▶
Index●
▶
XmlElementTree
▶
StaticPlots
▶
InteractivePlots
▶
Utilities
▶
StructureIO
▶
Widgets
▶
MainAPI
▶
SpinProjectedSurfaces
Install
pip install pivotpy
How to use
- Use commnad
pivotpy
in regular terminal to quickly launch documentation any time. - See Full Documentation.
- For CLI, use Vasp2Visual.
- See PDF Slides for detailed introduction.
Changelog for version 1.1.8+
Errors are properly handled now.
download_structure
returns list of structres for which output data can be access via attributes and methods on demand.
You can now use join_axes
to create desired layouts in plots.
Changelog for version 1.1.1
splot_[rgb,color,dos]_lines
and iplot_[rgb,dos]_lines
now accept another arguement query_data
which replaces elements, orbs, labels
if provided. This argument is a dictionary whose keys are replaced by labels
, last item in its values is in the form of (elements, orbs). It will be extend in future for fermi plots when you select individul bands as well.
These two are equivalent and later one is simplified with each item showing a single color/line:
plot_command(elements=[range(2),range(2)],orbs=[0,[1,2,3]],labels=['s','p'])
plot_command(query_data = {'s': (range(2),0),'p': (range(2),[1,2,3])}) # version >= 1.1.1
Changelog for version 1.0.10 onward
A new module api
is added which consists of selective functions and classes and it is enough for common user.
Now import pivotpy as pp
exports only whaterver is inside api
, access other modules separately.
CLI commnds
- Use
pivotpy
in system terminal to launch DOCS. - Use
pivotpy_get_poscar
to download POSCAR. - Use
pivotpy_get_kpath
to create fine controlled KPATH. - More to come.
New: Plot in Terminal without GUI
Use pp.plt2text(colorful=True/False)
after matplotlib's code and your figure will appear in terminal. You need to zoom out alot to get a good view like below.
Tip: Use file matplotlib2terminal.py on github independent of this package to plot in terminal.
New: Ipywidgets-based GUI
See GIF here:
New: Live Slides in Jupyter Notebook
Navigate to ipyslides or do pip install ipyslides
to create beautiful data driven presentation in Jupyter Notebook.
import os, pivotpy as pp
with pp.set_dir('E:/Research/graphene_example/ISPIN_1/bands'):
vr=pp.Vasprun(elim=[-5,5])
vr.data
Loading from PowerShell Exported Data...
VasprunData(
sys_info = Data(
SYSTEM = C2
NION = 2
NELECT = 8
TypeION = 1
ElemName = ['C']
E_Fermi = -3.3501
fields = ['s', 'py', 'pz', 'px', 'dxy', 'dyz', 'dz2', 'dxz', 'x2-y2']
incar = Data(
SYSTEM = C2
PREC = high
ALGO = N
LSORBIT = T
NELMIN = 7
ISMEAR = 0
SIGMA = 0.10000000
LORBIT = 11
GGA = PS
)
ElemIndex = [0, 2]
ISPIN = 1
)
dim_info = Data(
kpoints = (NKPTS,3)
kpath = (NKPTS,1)
bands = ⇅(NKPTS,NBANDS)
dos = ⇅(grid_size,3)
pro_dos = ⇅(NION,grid_size,en+pro_fields)
pro_bands = ⇅(NION,NKPTS,NBANDS,pro_fields)
)
kpoints = <ndarray:shape=(90, 3)>
kpath = <list:len=90>
bands = Data(
E_Fermi = -3.3501
ISPIN = 1
NBANDS = 21
evals = <ndarray:shape=(90, 21)>
indices = range(1, 22)
)
tdos = Data(
E_Fermi = -3.3501
ISPIN = 1
tdos = <ndarray:shape=(301, 3)>
)
pro_bands = Data(
labels = ['s', 'py', 'pz', 'px', 'dxy', 'dyz', 'dz2', 'dxz', 'x2-y2']
pros = <ndarray:shape=(2, 90, 21, 9)>
)
pro_dos = Data(
labels = ['s', 'py', 'pz', 'px', 'dxy', 'dyz', 'dz2', 'dxz', 'x2-y2']
pros = <ndarray:shape=(2, 301, 10)>
)
poscar = Data(
SYSTEM = C2
volume = 105.49324928
basis = <ndarray:shape=(3, 3)>
rec_basis = <ndarray:shape=(3, 3)>
positions = <ndarray:shape=(2, 3)>
labels = ['C 1', 'C 2']
unique = Data(
C = range(0, 2)
)
text_plain = C2 # Generated by Pivotpy
2.46803100000000
1.0000000000000000 0.0000000000000000 0.0000000000000000
-0.4999997974093519 0.8660251836382931 0.0000000000000000
0.0000000000000000 0.0000000000000000 8.1029342824300024
C
2
Direct
0.3333330000000000 0.6666670000000000 0.0000000000000000
0.6666670000000000 0.3333330000000000 0.0000000000000000
)
)
Matplotlib's static plots
- Add anything from legend,colorbar, colorwheel. In below figure, all three are shown.
- Use aliases such as sbands, sdos,srgb,irgb,scolor,idos for plotting.
#collapse_input
import pivotpy as pp, numpy as np
import matplotlib.pyplot as plt
vr1=pp.Vasprun('E:/Research/graphene_example/ISPIN_2/bands/vasprun.xml')
vr2=pp.Vasprun('E:/Research/graphene_example/ISPIN_2/dos/vasprun.xml')
axs = pp.get_axes(ncols=3,widths=[2,1,2.2],sharey=True,wspace=0.05,figsize=(8,2.6))
elements=[0,[0],[0,1]]
orbs=[[0],[1],[2,3]]
labels=['s','$p_z$','$(p_x+p_y)$']
ti_cks=dict(ktick_inds=[0,30,60,-1],ktick_vals=['Γ','M','K','Γ'])
args_dict=dict(elements=elements,orbs=orbs,labels=labels,elim=[-20,15])
vr1.splot_bands(ax=axs[0],**ti_cks,elim=[-20,15])
vr1.splot_rgb_lines(ax=axs[2],**args_dict,**ti_cks,colorbar=True,)
vr2.splot_dos_lines(ax=axs[1],vertical=True,spin='both',include_dos='pdos',**args_dict,legend_kwargs={'ncol': 3},colormap='RGB_m')
axs[2].color_wheel(xy=(0.7,1.15),scale=0.2,labels=[l+'$^{⇅}$' for l in labels])
pp._show()
[0;92m Given 0 at position 1 of sequence => 'C': range(0, 2). To just pick one ion, write it as [0].[00m
Interactive plots using plotly
args_dict['labels'] = ['s','p_z','p_x+p_y']
fig1 = vr1.iplot_rgb_lines(**args_dict)
#pp.iplot2html(fig1) #Do inside Google Colab, fig1 inside Jupyter
from IPython.display import Markdown
Markdown("[See Interactive Plot](https://massgh.github.io/InteractiveHTMLs/iGraphene.html)")
Brillouin Zone (BZ) Processing
- Look in
pivotpy.sio
module orpivotpy.api.POSCAR
class for details on generating mesh and path of KPOINTS as well as using Materials Projects' API to get POSCAR right in the working folder. Below is a screenshot of interactive BZ plot. You candouble click
on blue points and hitCtrl + C
to copy the high symmetry points relative to reciprocal lattice basis vectors. - 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.
- Any colored point's hover text is in gold background.
Look the output of pivotpy.sio.splot_bz
.
import pivotpy as pp
pp.sio.splot_bz([[1,0,0],[0,1,0],[0,0,1]],color=(1,1,1,0.2),light_from=(0.5,0,2),colormap='RGB').set_axis_off()
#pp.iplot2html(fig2) #Do inside Google Colab, fig1 inside Jupyter
from IPython.display import Markdown
Markdown("[See Interactive BZ Plot](https://massgh.github.io/InteractiveHTMLs/BZ.html)")
Plotting Two Calculations Side by Side
- Here we will use
shift_kpath
to demonstrate plot of two calculations on same axes side by side
#nbdev_collapse_input
import matplotlib.pyplot as plt
import pivotpy as pp
plt.style.use('bmh')
vr1=pp.Vasprun('E:/Research/graphene_example/ISPIN_1/bands/vasprun.xml')
shift_kpath=vr1.data.kpath[-1] # Add last point from first export in second one.
vr2=pp.Vasprun('E:/Research/graphene_example/ISPIN_2/bands/vasprun.xml',shift_kpath=shift_kpath,try_pwsh=False)
last_k=vr2.data.kpath[-1]
axs=pp.get_axes(figsize=(5,2.6))
K_all=[*vr1.data.kpath,*vr2.data.kpath] # Merge kpath for ticks
kticks=[K_all[i] for i in [0,30,60,90,120,150,-1]]
ti_cks=dict(xticks=kticks,xt_labels=['Γ','M','K','Γ','M','K','Γ'])
vr1.splot_bands(ax=axs)
vr2.splot_bands(ax=axs,txt='Graphene(Left: ISPIN=1, Right: ISPIN=2)',ctxt='m')
axs.modify_axes(xlim=[0,last_k],ylim=[-10,10],**ti_cks)
pp._show()
Loading from PowerShell Exported Data...
Interpolation
Amost every bandstructure and DOS plot function has an argument interp_nk
which is a dictionary with keys n
(Number of additional points between adjacent points) and k
(order of interpolation 0-3). n > k
must hold.
#collapse_input
import pivotpy as pp, matplotlib.pyplot as plt
plt.style.use('ggplot')
k = vr1.data.kpath
ef = vr1.data.bands.E_Fermi
evals = vr1.data.bands.evals-ef
#Let's interpolate our graph to see effect. It is useful for colored graphs.
knew,enew=pp.interpolate_data(x=k,y=evals,n=10,k=3)
plot = plt.plot(k,evals,'m',lw=5,label='real data')
plot = plt.plot(k,evals,'w',lw=1,label='interpolated',ls='dashed')
pp.splots.add_text(ax=plt.gca(),txts='Graphene')
LOCPOT,CHG Visualization
check out the class pivotpy.LOCPOT
to visulize local potential/charge and magnetization in a given direction.
Running powershell commands from python.
Some tasks are very tideious in python while just a click way in powershell. See below, and try to list processes in python yourself to see the difference!
pp.utils.ps2std(ps_command='(Get-Process)[0..4]')
[32;1m NPM(K) PM(M) WS(M) CPU(s) Id SI ProcessName[0m
[32;1m ------ ----- ----- ------ -- -- -----------[0m
22 6.96 2.50 0.67 16452 1 AcrobatNotificationClient
6 1.32 4.63 0.00 6864 0 AggregatorHost
19 7.57 12.31 0.00 4816 0 AppHelperCap
29 43.22 29.87 11.36 3844 1 ApplicationFrameHost
9 1.86 6.81 0.03 10072 1 AppVShNotify
Advancaed: Poweshell Cell/Line Magic %%ps/%ps
- You can create a IPython cell magic to run powershell commands directly in IPython Shell/Notebook (Powershell core installation required).
- Cell magic can be assigned to a variable
foo
by%%ps --out foo
- Line magic can be assigned to a variable by
foo = %ps powershell_command
Put below code in ipython profile's startup file (create one) "~/.ipython/profile_default/startup/powershell_magic.py"
from IPython.core.magic import register_line_cell_magic
from IPython import get_ipython
@register_line_cell_magic
def ps(line, cell=None):
if cell:
return get_ipython().run_cell_magic('powershell',line,cell)
else:
get_ipython().run_cell_magic('powershell','--out posh_output',line)
return posh_output.splitlines()
Additionally you need to add following lines in "~/.ipython/profile_default/ipython_config.py" file to make above magic work.
from traitlets.config.application import get_config
c = get_config()
c.ScriptMagics.script_magics = ['powershell']
c.ScriptMagics.script_paths = {
'powershell' : 'powershell.exe -noprofile -command -',
'pwsh': 'pwsh.exe -noprofile -command -'
}
%%ps
Get-ChildItem 'E:\Research\graphene_example\'
Directory: E:\Research\graphene_example
Mode LastWriteTime Length Name
---- ------------- ------ ----
da---- 11/28/2021 8:04 PM ISPIN_1
da---- 5/9/2020 1:05 PM ISPIN_2
-a---- 5/9/2020 1:01 PM 75331 OUTCAR
-a---- 5/9/2020 1:01 PM 240755 vasprun.xml
x = %ps (Get-ChildItem 'E:\Research\graphene_example\').Name
x
['ISPIN_1', 'ISPIN_2', 'OUTCAR', 'vasprun.xml']
<style>a{text-decoration: none !important;color:lightkblue;font-weight:bold;}
a:focus,a:active,a:hover{color:hotpink !important;}</style>
▶
Index●
▶
XmlElementTree
▶
StaticPlots
▶
InteractivePlots
▶
Utilities
▶
StructureIO
▶
Widgets
▶
MainAPI
▶
SpinProjectedSurfaces
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.