Python Processing Tool for Vasp Ipnut/Output

Overview

PivotPy

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

Run in Azure Open In Colab

  Index● 
  XmlElementTree 
  StaticPlots 
  InteractivePlots 
  Utilities 
  StructureIO 
  Widgets 

Install

pip install pivotpy

How to use

Changelog for version 0.9.5 onward

  • pivotpy.s_plots.splot_rgb_lines and pivotpy.s_plots.splot_rgb_lines are refactored and no more depnd on create_rgb_lines, so this function is dropped, If you still want to use it, use versions below 0.9.5.
  • A class pivotpy.g_utils.Vasprun is added which provides shortcut for export_vasprun and plotting functions. Under this class or as aliases:
    • splot_bands --> sbands
    • splot_rgb_lines --> srgb
    • iplot_rgb_lines --> irgb
    • splot_color_lines --> scolor
    • splot_dos_lines --> sdos
    • iplot_dos_lines --> idos
  • The plot functions starting with 'quick' or 'plotly' are still working but deprecated in favor of consistent names above starting from version 1.0.3.
  • A class pivotpy.g_utils.LOCPOT_CHG is added which can be used to parse and visualize files like LOCPOT and CHG.
  • A function pivotpy.vr_parser.split_vasprun is added which splits vasprun.xml file into a small file _vasprun.xml without projected data and creates text files _set[1,2,3,4].txt based on how many spin sets are there.
  • A function pivotpy.vr_parser.islice2array is added which can reads data from text/csv/tsv files (even if text and numbers are mixed) accoridng to slices you provide, this does not load full file in memory and it is also useful in parsing EIGENVAL, PROCAR like files with a few lines of code only.
  • Version 1.0.0 is updated with an overhaul of widgets module. VasprunApp is introduced as class to access internals of app easily.

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

New: Ipywidgets-based GUI

See GIF here: GIF

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
os.chdir('E:/Research/graphene_example/ISPIN_1/bands')
xml_data=pp.read_asxml()
vr=pp.export_vasprun(elim=[-5,5])
vr
Loading from PowerShell Exported Data...





Data(
    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 = 
   
    
    kpath = 
    
     
    bands = Data(
        E_Fermi = -3.3501
        ISPIN = 1
        NBANDS = 21
        evals = 
     
      
        indices = range(1, 22)
    )
    tdos = Data(
        E_Fermi = -3.3501
        ISPIN = 1
        tdos = 
      
       
    )
    pro_bands = Data(
        labels = ['s', 'py', 'pz', 'px', 'dxy', 'dyz', 'dz2', 'dxz', 'x2-y2']
        pros = 
       
         ) pro_dos = Data( labels = ['s', 'py', 'pz', 'px', 'dxy', 'dyz', 'dz2', 'dxz', 'x2-y2'] pros = 
        
          ) poscar = Data( SYSTEM = C2 volume = 105.49324928 basis = 
         
           rec_basis = 
          
            positions = 
           
             labels = ['C 1', 'C 2'] unique = Data( C = range(0, 2) ) ) ) 
           
          
         
        
       
      
     
    
   

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.export_vasprun('E:/Research/graphene_example/ISPIN_2/bands/vasprun.xml')
vr2=pp.export_vasprun('E:/Research/graphene_example/ISPIN_2/dos/vasprun.xml')
axs=pp.init_figure(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])
pp.splot_bands(path_evr=vr1,ax=axs[0],**ti_cks,elim=[-20,15])
pp.splot_rgb_lines(path_evr=vr1,ax=axs[2],**args_dict,**ti_cks,colorbar=True,)
pp.splot_dos_lines(path_evr=vr2,ax=axs[1],vertical=True,spin='both',include_dos='pdos',**args_dict,legend_kwargs={'ncol': 3},colormap='RGB_m')
pp.color_wheel(axs[2],xy=(0.7,1.15),scale=0.2,labels=[l+'$^{⇅}$' for l in labels])
pp._show() 
�[0;92m elements[0] = 0 is converted to range(0, 2) which picks all ions of 'C'.To just pick one ion at this index, wrap it in brackets [].�[00m


E:\Research\pivotpy\pivotpy\s_plots.py:457: MatplotlibDeprecationWarning:

shading='flat' when X and Y have the same dimensions as C is deprecated since 3.3.  Either specify the corners of the quadrilaterals with X and Y, or pass shading='auto', 'nearest' or 'gouraud', or set rcParams['pcolor.shading'].  This will become an error two minor releases later.

svg

Interactive plots using plotly

args_dict['labels'] = ['s','p_z','p_x+p_y']
fig1 = pp.iplot_rgb_lines(vr1,**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 for details on generating mesh and path of KPOINTS as well as using Materials Projects' API to get POSCAR right in the working folder with command get_poscar. 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. (You will be able to draw kpath in Pivotpy-Dash application and generate KPOINTS automatically from a web interface later on!).
  • 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

import pivotpy as pp 
pp.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)")

See Interactive BZ Plot

svg

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.export_vasprun('E:/Research/graphene_example/ISPIN_1/bands/vasprun.xml')
shift_kpath=vr1.kpath[-1] # Add last point from first export in second one.
vr2=pp.export_vasprun('E:/Research/graphene_example/ISPIN_2/bands/vasprun.xml',shift_kpath=shift_kpath,try_pwsh=False)
last_k=vr2.kpath[-1]
axs=pp.init_figure(figsize=(5,2.6))
K_all=[*vr1.kpath,*vr2.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','Γ'])
pp.splot_bands(path_evr=vr1,ax=axs)
pp.splot_bands(path_evr=vr2,ax=axs,txt='Graphene(Left: ISPIN=1, Right: ISPIN=2)',ctxt='m')
pp.modify_axes(ax=axs,xlim=[0,last_k],ylim=[-10,10],**ti_cks)
Loading from PowerShell Exported Data...

svg

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
plt.style.use('ggplot')
k=vr1.kpath
ef=vr1.bands.E_Fermi
evals=vr1.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.add_text(ax=plt.gca(),txts='Graphene')

svg

LOCPOT,CHG Visualization

check out the class pivotpy.LOCPOT_CHG 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.ps2std(ps_command='(Get-Process)[0..4]')
NPM(K)    PM(M)      WS(M)     CPU(s)      Id  SI ProcessName
------    -----      -----     ------      --  -- -----------
23     7.19       3.71       0.47   18012   1 AcrobatNotificationClient
15     4.05      11.25       0.34   15776   1 AdobeCollabSync
20     6.30      13.31       7.86   15820   1 AdobeCollabSync
15     5.12      12.90       0.00    5424   0 AppHelperCap
23    41.73      48.20       0.52    3800   1 ApplicationFrameHost

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----        10/31/2020   1:30 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']

Functions Reference

  Index● 
  XmlElementTree 
  StaticPlots 
  InteractivePlots 
  Utilities 
  StructureIO 
  Widgets 

Program Command Line Interface (CLI) Sederhana: Pemesanan Nasi Goreng Hekel

Program ini merupakan aplikasi yang berjalan di dalam command line (terminal). Program ini menggunakan built-in library python yaitu argparse yang dapat menerima parameter saat program ini dijalankan

Habib Abdurrasyid 5 Nov 19, 2021
A Reverse Shell Python Packages

A Reverse Shell Python Packages

1 Nov 03, 2021
Fast as FUCK nvim completion. SQLite, concurrent scheduler, hundreds of hours of optimization.

Fast as FUCK nvim completion. SQLite, concurrent scheduler, hundreds of hours of optimization.

i love my dog 2.8k Jan 05, 2023
Bear-Shell is a shell based in the terminal or command prompt.

Bear-Shell is a shell based in the terminal or command prompt. You can navigate files, run python files, create files via the BearUtils text editor, and a lot more coming up!

MichaelBear 6 Dec 25, 2021
Stream comments, submissions from subreddits and users across reddit right in your terminal

reddit_from_terminal stream comments, submissions from subreddits and users across reddit right in your terminal Alert! : Can't watch media contents(p

Pritam Dhara 2 Dec 30, 2021
The Prisma Cloud CLI is a command line interface for Prisma Cloud by Palo Alto Networks.

Prisma Cloud CLI The Prisma Cloud CLI is a command line interface for Prisma Cloud by Palo Alto Networks. Support This project has been developed by P

Palo Alto Networks 13 Oct 14, 2022
Python CLI utility and library for manipulating SQLite databases

sqlite-utils Python CLI utility and library for manipulating SQLite databases. Some feature highlights Pipe JSON (or CSV or TSV) directly into a new S

Simon Willison 1.1k Jan 04, 2023
gget is a free and open-source command-line tool and Python package that enables efficient querying of genomic databases.

gget is a free and open-source command-line tool and Python package that enables efficient querying of genomic databases. gget consists of a collection of separate but interoperable modules, each des

Pachter Lab 570 Dec 29, 2022
inklayers is a command line program that exports layers from an SVG file.

inklayers is a command line program that exports layers from an SVG file. It can be used to create slide shows by editing a single SVG file.

11 Mar 29, 2022
This project contains the ClonedPerson dataset and code described in our paper "Cloning Outfits from Real-World Images to 3D Characters for Generalizable Person Re-Identification".

ClonedPerson This is the official repository for the ClonedPerson project, which contains the ClonedPerson dataset and code described in our paper "Cl

Yanan Wang 55 Dec 27, 2022
A Python-based command prompt concept which includes windows command emulation.

PythonCMD A Python-based command prompt concept which includes windows command emulation. Current features: echo: Input your message and it will be cl

1 Feb 05, 2022
CLI program that allows you to change your Alacritty config with one command without editing the config file.

Pycritty Change your alacritty config on the fly! Installation: pip install pycritty By default, only the program itself will be installed, but you ca

Antonio Sarosi 184 Jan 07, 2023
🌈 Generate color palettes based on Neovim colorschemes.

Iris Iris is a Neovim plugin that generates a normalized color palette based on your colorscheme. It is named for the goddess Iris of Greek mythology,

N. G. Scheurich 45 Jul 28, 2022
Text based command line webcam photobooth app

Skunkbooth Why See it in action Usage Installation Run Media location Contributing Install Poetry Clone the repo Activate poetry shell Install dev dep

David Yang 45 Dec 26, 2022
This is a tool for managing file notes through the command line

This is a tool for managing file notes through the command line

2 Jun 22, 2022
A command line utility for tracking a stock market portfolio. Primarily featuring high resolution braille graphs.

A command line stock market / portfolio tracker originally insipred by Ericm's Stonks program, featuring unicode for incredibly high detailed graphs even in a terminal.

Conrad Selig 51 Nov 29, 2022
WebApp Maker make web apps (Duh). It is open source and make with python and shell.

WebApp Maker make web apps (Duh). It is open source and make with python and shell. This app can take any website and turn it into an app. I highly recommend turning these few websites into webapps:

2 Jan 09, 2022
A command-line utility that, given a markdown file, checks whether all its links work.

A command-line utility written in Python that checks validity of links in a markdown file.

Teclado 2 Dec 08, 2021
This is a CLI utility that allows you to view RedFlagDeals.com on the command line.

RFD Description Motivation Installation Usage View Hot Deals View and Sort Hot Deals Search Advanced View Posts Shell Completion bash zsh Description

Dave G 8 Nov 29, 2022
Simple script to download OTA packages from Realme's endpoint.

Realme OTA Downloader CLI tool (based on this C# program) to create requests to the Realme's endpoint. Requirements Python 3.9. pycryptodome. Installa

Roger Ortiz 64 Dec 28, 2022