Skip to content

Instantly share code, notes, and snippets.

@Asif-Iqbal-Bhatti
Created May 6, 2016 20:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Asif-Iqbal-Bhatti/d5e7c9f148176fe1478dcba0d778e80c to your computer and use it in GitHub Desktop.
Save Asif-Iqbal-Bhatti/d5e7c9f148176fe1478dcba0d778e80c to your computer and use it in GitHub Desktop.
Extract orbitals from VASP: PROCAR file
#!/bin/bash
#**************************************************************************************************#
# #
# Created on 06/05/2016 at 02:00 PM #
# Author: Asif Iqbal Bhatti #
# Extracting site projected orbitals for a selected atom #
# Usage: Run the file in the directory where VASP files are located !!! #
# #
#**************************************************************************************************#
#**************************************BACKGROUND***************************************************
#The LDOS, or local density of states, is the the density of state at a particular site of a crystal
#with some asymetry. For example: A slab will have a different band structure on the surface than
#in the bulk region.
#
#The PDOS is a projected density of states. In the context of VASP this means site-projected DOS,
#where the information about the different contributions of the different orbitals is computed.
#You then know which states (spd) contribute at which energy. Select the proper LORBIT
#tag in the INCAR file (e.g. LORBIT=11) to get the spd decomposed DOSCAR file output.
#***************************************************************************************************
# MAIN PURPOSE OF THE SCRIPT
# This code extracts from PROCAR at which energy, particular atom [s, p and d] orbitals contributed.
#***************************************************************************************************
echo > *.dat
export POSCAR="POSCAR"
export PROCAR="PROCAR"
export OUTCAR="OUTCAR"
if [[ -e $PROCAR || -e $POSCAR || -e $OUTCAR ]];
then
echo " **************************************************"
echo " Usage : Run only $0 before giving any arguments to select "
echo " which atom projections to write to a file and then run "
echo " $0 atom_number orbital_type [s, p or d]"
echo " POSCAR & PROCAR read "
echo " Initializing ... "
echo " **************************************************"
# Total number of atom types
declare -a ATOM_TYPE=(`sed -n '7 p' $POSCAR`)
export ATOM_TYPE_TOTAL=${#ATOM_TYPE[@]}
# Total number of atoms
ATOMS_TOTAL=0
i=0
while [[ "$i" -lt "$ATOM_TYPE_TOTAL" ]]
do
export iATOM_TYPE=${ATOM_TYPE[$i]}
export ATOMS_TOTAL=`expr $ATOMS_TOTAL + $iATOM_TYPE`
export i=`expr $i + 1`
done
#
# Atom labels
declare -a ATOM_LABEL=(`grep "POTCAR:" $OUTCAR | head -$ATOM_TYPE_TOTAL | awk '{print $3}' | sed -e 's/_.*//g'`)
export ATOM_LABEL_TOTAL=${#ATOM_LABEL[@]}
# Print2Screen
echo
echo " Number of Atom Types :" $ATOM_TYPE_TOTAL
echo " Atom Type :" ${ATOM_LABEL[@]}
echo " Atom Type Count :" ${ATOM_TYPE[@]}
echo " Total Number of Atoms :" $ATOMS_TOTAL
if [ ! -z "$1" ]; # logical statemnet to check if the argument exist
then
#**********************************d-orbital***********************************************
if [ "$2" == "d" ];
then
Anum=`cat $POSCAR | tail -n +9 | sed -n 1,"$ATOMS_TOTAL"p | wc -l`
echo " Verifying total number of coordinates in the POSCAR file $Anum "
Acoord=`cat $POSCAR | tail -n +9 | sed -n 1,"$ATOMS_TOTAL"p | sed -n "$1"p`
echo " Selected Atom coordinates are ($Acoord)"
cm=`grep -w "ion" $PROCAR | head -1 | awk '{printf "%3s %7s %8s %8s %8s %8s %8s\n", $1, $6, $7, $8, $9, $10, $11}'`
echo "$cm" > d_spinup.dat
echo "$cm" > d_spindown.dat
echo
echo " ---> Writing data to spinup.dat file"
bu=`cat $PROCAR | grep "# of bands" | head -1 | awk '{printf "%d", $8}'`
cat $PROCAR | tail -n +8 | sed '/^[ion,band,tot]/d' | sed '/^\s*$/d' | awk '{printf "%d %f %f %f %f %f %f\n", $1, $6, $7, $8, $9, $10, $11}' | grep "$1" | head -n $bu >> ".dsu"
echo " ---> Writing data to spindown.dat file"
bd=`cat $PROCAR | grep "# of bands" | tail -1 | awk '{printf "%d", $8}'`
cat $PROCAR | tail -n +8 | sed '/^[ion,band,tot]/d' | sed '/^\s*$/d' | awk '{printf "%d %f %f %f %f %f %f\n", $1, $6, $7, $8, $9, $10, $11}' | grep "$1" | tail -n $bd >> ".dsd"
i=1
while [[ $i -le $bu ]];
do
echo $i >> ".count"
i=$(bc <<< "$i + 1")
done
cat .dsu | cut -d " " -f 2- > ".dsu_bak"
paste ".count" ".dsu_bak" >> d_spinup.dat
cat .dsd | cut -d " " -f 2- > ".dsd_bak"
paste ".count" ".dsd_bak" >> d_spindown.dat
fi
#**********************************p-orbital***********************************************
if [ "$2" == "p" ];
then
Anum=`cat $POSCAR | tail -n +9 | sed -n 1,"$ATOMS_TOTAL"p | wc -l`
echo " Verifying total number of coordinates in the POSCAR file $Anum "
Acoord=`cat $POSCAR | tail -n +9 | sed -n 1,"$ATOMS_TOTAL"p | sed -n "$1"p`
echo " Selected Atom coordinates are ($Acoord)"
cm=`grep -w "ion" $PROCAR | head -1 | awk '{printf "%3s %7s %8s %8s %8s\n", $1, $3, $4, $5, $11}'`
echo "$cm" > p_spinup.dat
echo "$cm" > p_spindown.dat
echo
echo " ---> Writing data to spinup.dat file"
bu=`cat $PROCAR | grep "# of bands" | head -1 | awk '{printf "%d", $8}'`
cat $PROCAR | tail -n +8 | sed '/^[ion,band,tot]/d' | sed '/^\s*$/d' | awk '{printf "%d %f %f %f %f\n", $1, $3, $4, $5, $11}' | grep "$1" | head -n $bu >> ".psu"
echo " ---> Writing data to spindown.dat file"
bd=`cat $PROCAR | grep "# of bands" | tail -1 | awk '{printf "%d", $8}'`
cat $PROCAR | tail -n +8 | sed '/^[ion,band,tot]/d' | sed '/^\s*$/d' | awk '{printf "%d %f %f %f %f\n", $1, $3, $4, $5, $11}' | grep "$1" | tail -n $bd >> ".psd"
i=1
while [[ $i -le $bu ]];
do
echo $i >> ".count"
i=$(bc <<< "$i + 1")
done
cat .psu | cut -d " " -f 2- > ".psu_bak"
paste ".count" ".psu_bak" >> p_spinup.dat
cat .psd | cut -d " " -f 2- > ".psd_bak"
paste ".count" ".psd_bak" >> p_spindown.dat
fi
#**********************************s-orbital***********************************************
if [ "$2" == "s" ];
then
Anum=`cat $POSCAR | tail -n +9 | sed -n 1,"$ATOMS_TOTAL"p | wc -l`
echo " Verifying total number of coordinates in the POSCAR file $Anum "
Acoord=`cat $POSCAR | tail -n +9 | sed -n 1,"$ATOMS_TOTAL"p | sed -n "$1"p`
echo " Selected Atom coordinates are ($Acoord)"
cm=`grep -w "ion" $PROCAR | head -1 | awk '{printf "%3s %7s %7s\n", $1, $2, $11}'`
echo "$cm" > s_spinup.dat
echo "$cm" > s_spindown.dat
echo
echo " ---> Writing data to spinup.dat file"
bu=`cat $PROCAR | grep "# of bands" | head -1 | awk '{printf "%d", $8}'`
cat $PROCAR | tail -n +8 | sed '/^[ion,band,tot]/d' | sed '/^\s*$/d' | awk '{printf "%d %f %f\n", $1, $2, $11}' | grep "$1" | head -n $bu >> ".ssu"
echo " ---> Writing data to spindown.dat file"
bd=`cat $PROCAR | grep "# of bands" | tail -1 | awk '{printf "%d", $8}'`
cat $PROCAR | tail -n +8 | sed '/^[ion,band,tot]/d' | sed '/^\s*$/d' | awk '{printf "%d %f %f\n", $1, $2, $11}' | grep "$1" | tail -n $bd >> ".ssd"
i=1
while [[ $i -le $bu ]];
do
echo $i >> ".count"
i=$(bc <<< "$i + 1")
done
cat .ssu | cut -d " " -f 2- > ".ssu_bak"
paste ".count" ".ssu_bak" >> s_spinup.dat
cat .ssd | cut -d " " -f 2- > ".ssd_bak"
paste ".count" ".ssd_bak" >> s_spindown.dat
fi
fi
else
echo " Enter atoms number to project on the d-orbitals"
echo " Usage : $0 atom_number orbital_type [s, p or d]"
echo " ERROR : PROCAR || POSCAR || Atom number missing"
echo
exit
fi
rm -f .d* .s* .p* .count
@sullah12
Copy link

sullah12 commented Apr 3, 2018

Hello ,
I want to make band structure from PROCAR file in VASP .
I need a script for band structure from PROCAR.
I already used extract_procar.sh this script and I got *.dat file .
Q. What can I do now? to get the band structure with s p d orbitals.
Thanks in advance .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment