Skip to the content.

Vasp2Visual 🟢   pivotpy 🔴   Interactive Plot   Jupyter Notebook   Grid Plot   Run in Azure

Vasp2Visual

A Pre/Post processing PowerShell Module for Vasp output. Scripts allow user take full control of their vasp output data. You can plot on your own by just getting data in column format through using the command Export-VaspRun in a folder containing vasprun.xml.



PS> Get-Command -Module Vasp2Visual
CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Function        Enable-SelectiveDynamics                           1.0.3.0    Vasp2Visual
Function        Export-LOCPOT                                      1.0.3.0    Vasp2Visual
Function        Export-VaspRun                                     1.0.3.0    Vasp2Visual
Function        Get-FillingWeights                                 1.0.3.0    Vasp2Visual
Function        Get-Summary                                        1.0.3.0    Vasp2Visual
Function        Get-EigenVals                                      1.0.3.0    Vasp2Visual
Function        Get-KPath                                          1.0.3.0    Vasp2Visual
Function        Merge-ToSlab                                       1.0.3.0    Vasp2Visual
Function        Get-FigArgs                                        1.0.3.0    Vasp2Visual
Function        New-Figure                                         1.0.3.0    Vasp2Visual
Function        New-Presentation                                   1.0.3.0    Vasp2Visual
Function        Out-Path                                           1.0.3.0    Vasp2Visual
Function        Read-BigFile                                       1.0.3.0    Vasp2Visual
Function        Write-BigStream                                    1.0.3.0    Vasp2Visual


Interactive Plot   Jupyter Notebook   Grid Plot


Plot using New-Figure command

There are multiple switches for interactive and static plots including sRGB, iRGB etc. You can access all switches and parameters using Tab.

Note: You need python >= 3.6 to use this command and pivotpy module. ```powershell ❯ Get-Help New-Figure

NAME New-Figure

SYNTAX New-Figure [[-sRGB]] [-VasprunFile ] [-FigArgs ] [-SavePDF ] [-SavePNG ][-SavePyFile ] []

New-Figure [[-iDOS]] [-VasprunFile <Object>] [-FigArgs <hashtable>] [-SaveHTML <Object>] [-SaveMinHTML <Object>][-SavePyFile <Object>] [<CommonParameters>] ```
 $x = Get-FigArgs -sBands
Name                           Value
----                           -----
kseg_inds                      []
figsize                        (3.4, 2.6)
xytxt                          [0.05, 0.9]
txt                            None
ktick_inds                     []
E_Fermi                        None
elim                           []
skipk                          None
ctxt                           'black'
ktick_vals                     []
 New-Figure -VasprunFile 'E:\Research\graphene_example\ISPIN_2\bands\vasprun.xml' -sBands -FigArgs $x -SavePDF 'fig.pdf' -SavePyFile 'fig.py'

You can edit the saved python file for further tweaking. Also note that if you want a string placed in python, like ctxt = 'red' in Get-FigArgs, you have to modify it as $x.ctxt = " 'red' ", double qoutes for powershell and single qoutes will be written in python file.

 New-Figure -sRGB -AfterCode "ax.set_ylabel('')`nax.grid(axis='x')`nplt.subplots_adjust(left=0.2)"
  #This will add following lines after plot command:
    ax.set_ylabel('')
    ax.grid(axis='x')
    plt.subplots_adjust(left=0.2)
  #Use powershell's new line character `n instead of pythons's \n in code. Keep track of indentation too. 

PS Export-VaspRun -InputFile .\vasprun.xml -SkipK 10 -MaxFilled 5 -MaxEmpty 5
# You can add switch -OnlyDOS to this function.

Export-VaspRun

Piping in Powershell

In a big project where you have multiple files in same depth (or anyway you can think of) You can use pipe operator to avoid for loops and run data or save figures in all folders by just running 1 liner.

PS Resolve-Path **/**/vasprun.xml | Export-VaspRun
# This exported 4 files in one run
PS Resolve-Path **/**/vasprun.xml | New-Figure -sBands -SavePNG 'myfig.png'
# This saves figures in corresponding directories.

Use Get-POSCAR to acess POSCAR from Materials Project

You need Materials Project API to access their data. Function will return a list of available POSCARs for given structure. Access data using get_poscar from pivotpy directly on remote server. To save APIKey for autolad, open python terminal and use pivotpy.sio.save_mp_API('your_api_key'), in that case you do not need to provide api key yourself each time.

 $x = Get-POSCAR 'GaAs' -APIKey '*****' -MaxSites 8
 $x[0].poscar
GaAs  # Generated by PivotPy using Materials Project Database.
  4.06599269
     1.0000000000000000     0.0000000000000000     0.0000000000000000
     0.5000000000490150     0.8660254037561398     0.0000000000000000
     0.5000000000490150     0.2886751346042458     0.8164965780265512
  Ga  As
  1   1
Direct
  0.00000000    0.00000000    0.00000000  Ga
  0.75000000    0.75000000    0.75000000  As

PS> $x=Read-BigFile -FilePath E:\Research\Current\pDOS.txt -StopIndex 5
PS> Write-BigStream -StreamArray $x -FilePath E:\Research\Current\new.txt -AsOneLine

Get-IntoYourWorkStation



C:\Users\mass_\Documents\WindowsPowerShell\Modules;
C:\Program Files\WindowsPowerShell\Modules;
C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules

After Installation Steps



Get-FunctionsWork

To import Vasp2Visual and see if it is available in current session, run

PS> Import-Module Vasp2Visual
PS> Get-Module  #will give all imported modules including the one you just imported
Script     1.0.0.0    Vasp2Visual                         {Close-Writers, Get-KPath, Get-Plot, Get-PlotArguments...}

To permanently import it into your profile, run the following cmdlet

PS> "Import-Module Vasp2Visual"|Add-Content $PROFILE

If you are working in WSL on windows, you probably encounter switching between windows and linux terminals, so here is a function that changes the current windows directory path into Linux and LaTeX path formats.

PS> Out-Path -AbsolutePath ./GaAs
Name                           Value
----                           -----
LinuxPath                      /mnt/Full Path Required for WSL./GaAs
LatexPath                      ./GaAs
PythonPath                      ./GaAs
OnClipboard                    /mnt/Full Path Required for WSL./GaAs
#So you need absolute path to enter in WSL from powershell. LaTeX path is fine.

Get-KPath

Vasp2Visual contains a cmdlet for creating a K-Path before you run a calculation on vasp(HSE specifically). You can provide path to IBZKPT file to include as well.

 Get-Help Get-KPath
SYNTAX
    Get-KPath [-HSK_Array] <array> [[-n] <int>] [[-Labels_Array] <array>] [[-Weight]        
    <Object>] [[-OutFile] <Object>] [[-IBZKPT_File] <Object>] [<CommonParameters>]
 Get-KPath -HSK_Array @(((1,3,4,5),(2,3,4)),((1,3,4),(2,3,4))) -Labels_Array "l","g|k","x"
Automatically generated using PivotPy with HSK-INDS = [0, 5, -1], LABELS = ['l', 'g|k', 'x'], SEG-INDS = [5]
	15
  ...

If you have disconnected path, you need an array as in above example, each path is just a pair of two points. If you only require single path patch, use 2D array as given below:

 Get-KPath -HSK_Array @((1,3,4,5),(2,3,4),(1,3,4),(2,3,4)) -Labels_Array "l","g","k","x"
Automatically generated using PivotPy with HSK-INDS = [0, 5, 15, -1], LABELS = ['l', 'g', 'k', 'x'], SEG-INDS = []
	25
  ...

Another aspect of Get-KPath is that you can have custom number of points in an interval, just add a 4th entry in left point as I added 5 in first point. Otherwise parameter -n is number of points per unit length and all kpoints are uniformly distributed based on distance of intervals.


For accessing any entry of a tabular data file, you can use the following command

PS> Format-DataInFile .\Bands.txt -ViewAsExcel -DispalyFewColumns -SelectColumns 1,2,3,4,5

which gives output in an Excel-like window as shown below. You can apply sorting operation in this window and much more. Theoretically you can see any file this way without opening any editor or a big program like Excel.


In case you want to access a data entry in column_5, you can view it as an indexed dataframe.

PS> (Format-DataInFile .\Bands.txt).B1[0]                                         
    -14.0141

DataView


Collect-VaspData

In order to collect data from vasprun.xml, run the command

PS> Export-VaspRun
#For a system with NBANDS > 40, it will prompt to select a range of bands
[SYSTEM] structure contains  64 ions and 780 bands.           
 [To get all bands, Type 530, 250] ⇚ OR ⇛ [Collect almost ↑↓ 30 bands around VBM]
 Seperate entries by a comma: e.g. 530, 250                         
 NBANDS_FILLED, NBANDS_EMPTY: 15,10 

This will make 4 files, Bands.txt, tDOS.txt, pDOS.txt, Projection.txt and a SysInfo.py file that can be imported in python directly. Projections are written ion-wise in same file.

If running the above cmdlet throws an error and stops running, then you must run the following command

PS> Close-Writers #This will close all opened stream writers. 

Now you are able to use your own plotting method to get output, but you can instead use Get-Plot function to let it work automatically for you. Before going forward, lets get to know how many arguments are available and then you can just edit arguments.

PS> $x=Get-PlotArgs  # Use switches -DOS,-Plotly, Default retrurn is for basic plots.
PS> $x.E_Limit="[-10,15]" #sets your defined energy limit in plot
PS> $x.ticklabels  #will show up ticklabels and you can edit
#After editing all keys in $x.Key for your system, you can run the following cmdlet to get plot
PS> Get-Plot -ProjectedBandDOS -PlotArguments $x #will output a plot. You can add -HalfColumnWide switch to make small size plots.

Export LOCPOT file into seperate x,y,z-directed potentials using

PS> Export-LOCPOT #Creates three plane data files consisting minimum,maximum and average potential in each direction.
PS> Get-ConvolvedPotential -X_Dir -V_max -Interval 1,20 #gives interactive plotly graph in html format. 
PS> Get-AlignedPotential -Z_Dir -V_min -LeftRightPositions 0.25,0.75 -Periodicity 28 -LeftRightNames 'left','right'

Aligned potential looks like the below one. AlignPlot


Get-PublicationsReadyPlots


Get-More

The most useful cmdlet is Get-InteractivePlot based on Plotly. You can interact with html graph, can switch between simple and projected plots and can get coordinates visually.


Here is how it works.

PS> $x=Get-PlotArgs -Plotly; $x
Name                           Value
----                           -----
tickIndices                    [0,30,60,90,-1]
ticklabels                     [u'\u0393','M','K',u'\u0393','A']
E_Limit                        [5,-5]
ProLabels                      ['Ga','s','p','d']
ProIndices                     [(range(0,1,1)),(0,),(1,2,3,),(4,5,6,7,8,)]

You can edit any key, and get plot using the cmdlet

PS> Get-InteractivePlot -PlotlyHashTable $x

If you have disconnected K-path, you can join it in figure automatically be using $x.JoinPathAt="[break points indices array]" in plot arguments $x=Get-Args -switches. Say we have 'L' and 'M' points at index 19,20 and do not have kpoints between them, we can just set $x.JoinPathAt="[20]" and plotting function will do the job automatically.


Name                           Value                                           
----                           -----                                           
textLocation                   [0.05,0.9]                                      
DOS_Limit                      [0.0,0.6]                                       
FigureHeight                   2.5                                             
E_Limit                        [5,-5]                                          
ProLabels                      ['Ga','s','p','d']                              
ProIndices                     [(range(0,1,1)),(0,),(1,2,3,),(4,5,6,7,8,)] 

You can edit any key using $x.key="value" and get DOS plot using the cmdlet

PS> Get-DensityPlot -LinePlot $x -HalfColumnWide
Required files not found. Generating using 'Export-VaspRun' ...
Files now exist. Plotting ...

Get-Automated



PS> Merge-ToSlab -FirstPOSCAR .\slab.vasp -SecondPOSCAR .\slab.vasp #Merges two POSCARS in z-direction
Only Cubic and Tetragonal POSCARs are supported.
Make sure your POSCARs DO NOT have non-zero xz,yz,zx,zy elements,
If so, first rotate POSCAR using Vesta.
File [POSCAR_New.vasp] created.

File [POSCAR_eSD.vasp] is created.
PS> Disable-SelectiveDynamics -InputPOSCAR .\POSCAR_eSD.vasp
File [POSCAR_dSD.vasp] is created.

XY_PlaneSites YZ_PlaneSites ZX_PlaneSites
------------- ------------- -------------
{1, 2, 5, 6}  {1, 4, 6, 7}  {1, 3, 5, 7}


X_AtLayers               Y_AtLayers               Z_AtLayers
----------               ----------               ----------
{0.00, 0.25, 0.50, 0.75} {0.00, 0.25, 0.50, 0.75} {0.00, 0.25, 0.50, 0.75}

Name                           Value                                           
----                           -----                                           
Minimum                        -0.1617                                         
Maximum                        3.3817                                          
BandNumber                     9                                               
K_min                          75                                              
K_max                          25

PS> Get-IndexedPlot 30,-20 -xTickDistance 25 #Creates the plot with bands and k-point indexed as givnen in figure below.

IndexedPlot


PS> Find-GapOfBands 10 9 #returns band gap. 

Above command Can return bandwidth if smaller index is first say 9 10, or of same band 9 9. This is extemely useful to find the Bandwith between VBM and Minimim value of energy on lowest band. try:

PS> Find-GapOfBands 1 9
17.4247
BandWidth (1 → 9): 17.4247 eV is copied to clipboard.

Name                           Value                                           
----                           -----                                           
Point_1                        {0.8660, 3.3817}                                
Point_2                        {0.8660, 3.3817}                                
Distance                       0                                               
Distance: 0 [dimensionless] is copied to clipboard.

Present-It

The Beamer-Timer is available as standslone repository but it is included in this package as well. You can get a beamer presenatation file immediately in your working folder by running

PS> New-Presentation -Blank #or use -Template switch

This will generate a main.tex file. You can create a loop in powershell to make slides automatically for your all pictures in subdirectories.


You will get a bonus Reveal-Markdown directory containing a reveal.md file and a theme myserif.css. If you have vscode-reveal extension installed on VSCode, you can create interactive HTML presentation just using markdown and can also convert it to PDF and static HTML website like revealjs.


Time Beam


Vasp2Visual 🟢   pivotpy 🔴  

Run in Azure