Skip to main content

PivotPy

A Python Processing Tool for Vasp Input/Output. A CLI is available in Powershell, see Vasp2Visual.

Run in Azure Open In Colab

<style>a{text-decoration: none !important;color:lightkblue;font-weight:bold;} a:focus,a:active,a:hover{color:hotpink !important;}</style>

 ▶ Index● 
 ▶ Example 
 ▶ StaticPlots 
 ▶ InteractivePlots 
 ▶ SpinProjectedSurfaces 
 ▶ StructureIO 
 ▶ Widgets 
 ▶ MainAPI 

Install

pip install pivotpy

How to use

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.

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. IMG

Ipywidgets-based GUI

See GIF here: GIF

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])

print('Try Follwing Methods:')
for v in dir(vr):
    if not v.startswith('_'):
        print('vr.'+v)
Try Follwing Methods:
vr.Fermi
vr.data
vr.elim
vr.fermi
vr.get_band_info
vr.get_en_diff
vr.get_fermi
vr.iplot_dos_lines
vr.iplot_rgb_lines
vr.kticks
vr.poscar
vr.select
vr.splot_bands
vr.splot_color_lines
vr.splot_dos_lines
vr.splot_en_diff
vr.splot_rgb_lines
vr.to_json
vr.to_pickle
import matplotlib.pyplot as plt 
ax1,ax2 = pp.get_axes((6,3),ncols=2)
ax1.plot(vr.data.scsteps['e_fr_energy'],lw=3, label = 'e_fr_energy',color='k')
ax1.plot(vr.data.scsteps['e_0_energy'],lw=0.7,ls='dashed',label='e_0_energy',color='skyblue')
ax1.set_ylabel('Energy (eV)')
ax1.set_xlabel('Iteration Number')
ax1.legend()

vr.poscar.splot_lat(ax=ax2,plane='xy')
X, Y, Z = vr.data.poscar.coords.T
q = ax2.quiver(X,Y,*vr.data.force[:,:2].T,scale=25,color='r')
ax2.quiverkey(q, 0.7, 1, 7, 'Force (arb. units)')
ax2.add_legend()

svg

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],[2],[1,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],colormap='viridis',)
vr1.splot_bands(ax=axs[0],**ti_cks,elim=[-20,15])
vr1.splot_rgb_lines(ax=axs[2],**args_dict,**ti_cks,colorbar=False)
vr2.splot_dos_lines(ax=axs[1],vertical=True,spin='both',include_dos='pdos',**args_dict,legend_kwargs={'ncol': 3})
axs[2].color_cube(loc=(0.7,0.25),size=0.35)
pp._show() 
 Given 0 at position 1 of sequence => 'C': range(0, 2). To just pick one ion, write it as [0].

svg

Interactive plots using plotly

args_dict['labels'] = ['s','p_z','p_x+p_y']
args_dict.pop('colormap')
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)")

See Interactive Plot

Brillouin Zone (BZ) Processing

  • Look in pivotpy.sio module or pivotpy.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 can double click on blue points and hit Ctrl + 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.

BZ Energy See Interactive BZ Plot

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.Fermi
evals = vr1.data.bands.evals.SpinUp - 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')

svg

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]')
 NPM(K)    PM(M)      WS(M)     CPU(s)      Id  SI ProcessName
 ------    -----      -----     ------      --  -- -----------
22     6.92       8.27       0.33   14100   1 AcrobatNot…
6     1.29       5.68       0.00    7724   0 Aggregator…
19     7.22      20.85       0.00    5608   0 AppHelperC…
26    39.25      57.59       0.48    2064   1 Applicatio…
9     1.67       6.88       0.00    5264   0 armsvc

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----          6/9/2022  10:33 AM                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']

Functions Reference

<style>a{text-decoration: none !important;color:lightkblue;font-weight:bold;} a:focus,a:active,a:hover{color:hotpink !important;}</style>

 ▶ Index● 
 ▶ Example 
 ▶ StaticPlots 
 ▶ InteractivePlots 
 ▶ SpinProjectedSurfaces 
 ▶ StructureIO 
 ▶ Widgets 
 ▶ MainAPI 

Release files for pivotpy 1.3.11

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pivotpy 1.3.11
File Size Uploaded
pivotpy-1.3.11.tar.gz 126.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pivotpy 1.3.11
File Interpreter ABI Platform
pivotpy-1.3.11-py3-none-any.whl Python 3 none any Details

Total release size: 305.1 kB

Release files / pivotpy-1.3.11.tar.gz

Download URL pivotpy-1.3.11.tar.gz
Size 126.7 kB
Tags Source
SHA-256 checksum
How to use checksums
207101e5223aaed0888d75f68d0fb8228e7227f47987f4de953ddcb312b24d3d
BLAKE2b-256 checksum
How to use checksums
e7b7d765050b50bffeb5133b59ee94433e54b47c4992e49a16a66f1f8f5c92a6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/57.4.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.6

Release files / pivotpy-1.3.11-py3-none-any.whl

Download URL pivotpy-1.3.11-py3-none-any.whl
Size 178.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f9b2ec90279b8f9b39734ddc763b795f91fd92c702cdc8e7e52a50c3a73c9821
BLAKE2b-256 checksum
How to use checksums
964b2dbacd69d2f7cfef75ca5f1199f7122bb933ec84b48def2cacef785b49f3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/57.4.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.6

Release history Release notifications | RSS feed

This release

1.3.11 This release

2 release files

1.3.9

2 release files

1.3.8

2 release files

1.3.7

2 release files

1.3.6

2 release files

1.3.5

2 release files

1.3.4

2 release files

1.3.3

2 release files

1.3.2

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.12

2 release files

1.2.11

2 release files

1.2.10

2 release files

1.2.9

2 release files

1.2.8

2 release files

1.2.7

2 release files

1.2.6

2 release files

1.2.5

2 release files

1.2.4

2 release files

1.2.3

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.14

2 release files

1.1.13

2 release files

1.1.12

2 release files

1.1.11

2 release files

1.1.10

2 release files

1.1.9

2 release files

1.1.8

2 release files

1.1.7

2 release files

1.1.5

2 release files

1.1.4

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.13

2 release files

1.0.11

2 release files

1.0.10

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.9.20

2 release files

0.9.16

2 release files

0.9.12

2 release files

0.9.9

2 release files

0.9.8

2 release files

0.9.5

2 release files

0.9.3

2 release files

0.9.2

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.5

2 release files

0.8.3

2 release files

0.8.2

2 release files

0.8.0

2 release files

0.7.6

2 release files

0.7.5

2 release files

0.7.4

2 release files

0.7.3

2 release files

0.7.2

2 release files

0.7

2 release files

0.6

2 release files

0.5.0

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.9

2 release files

0.3.8

2 release files

0.3.7

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page