Last active
June 23, 2017 15:13
-
-
Save aditya95sriram/662f621b7b5c0c80c44d72c0d20f82de to your computer and use it in GitHub Desktop.
Converts all .dat binary files output by Quantum Espresso to human readable .xml using IOTK
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Script to convert binary data in .dat files to .xml files | |
# using Quantum Espresso Input Output Toolkit (iotk) | |
# ========================================================= | |
# | |
# NOTE: Set IOTK directory on line 24 before using | |
# e.g. <espresso>/bin/iotk, where <espresso> is the path to Quantum Espresso | |
# | |
# Recommended Usage: | |
# - Place script in home directory (optional) | |
# - navigate to *.save directory generated by Espresso | |
# - run `~/dat2xml.sh` | |
# | |
# What it does: | |
# - Saves loaded modules before purging them (some modules conflict with iotk) | |
# - Convert gvectors.dat and charge-density.dat | |
# - Go through all the k-point directories | |
# - Convert evc.dat and gkvectors.dat | |
# - Restore the previously purged modules | |
# | |
# created: Austin Liu | |
# modified: P. R. Vaidyanathan | |
# report bugs : aditya95sriram <at> gmail <dot> com | |
IOTK='<path>/espresso-5.3.0/bin/iotk' | |
DIR="$( pwd )" | |
# save previously loaded modules | |
prev=$(module list -t 2>&1 | tail -n +2) | |
if [ -n "$prev" ]; then | |
echo "saving loaded modules (" $prev ") before purging" | |
fi | |
# purge modules, don't need any for IOTK | |
module purge | |
# save iotk default output | |
iotk_out=$($IOTK 2>&1 | head -n 1) | |
# convert a file given path and filename(without extension) as parameters | |
function convert { | |
printf " converting $2.dat =>" | |
s=$($IOTK convert "$1/$2.dat" "$1/$2.xml" 2>&1) | |
# compare output with default output to check for errors | |
if [ "$s" == "$iotk_out" ]; then | |
# no errors | |
echo " $2.xml" | |
else | |
echo | |
echo "Error while converting:" | |
echo "$s" | |
fi | |
} | |
echo "using iotk from $IOTK" | |
echo "working in $DIR" | |
convert $DIR gvectors | |
convert $DIR charge-density | |
# works as long as K***** is the naming pattern | |
#for d in $(ls | grep '\<K.....\>'); do | |
# works as long as K* is the naming pattern, | |
# might harmlessly tread into other K* directories | |
for d in $(ls -d K*); do | |
DIR_K="$DIR/$d" | |
echo "entering directory $DIR_K" | |
convert $DIR_K evc | |
convert $DIR_K gkvectors | |
done | |
if [ -n "$prev" ]; then | |
# restore loaded modules | |
printf "restoring loaded modules (" | |
for mod in $prev; do | |
module load $mod | |
printf " $mod " | |
done | |
echo ")" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment