-
Notifications
You must be signed in to change notification settings - Fork 0
/
arrange_bands_spin.sh
executable file
·119 lines (94 loc) · 4 KB
/
arrange_bands_spin.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/bash
###############################################################
####################### Descriptions ##########################
# This script reads in spin.*.dat produced by spinor_pw2bgw.x
# and eqp.dat output by qouteig_eqp.dat or BGW, and then it will
# combine these two files to get a new eqp.spin.dat with the last
# two columnes corresponding to spin polarization along one direction
###############################################################
#Author: Meng Wu, Ph.D. Candidate in Physics
#Affiliation: University of California, Berkeley
# ------
#Version: 1.0
#Date: Nov. 30, 2017
######################### Variables ###########################
version='1.0'
QEINPUT="QE.in"
QEOUTPUT="QE.out"
INFILE="QE.out"
EIGFILE="eqp.mf.dat"
SPINFILE="spin.z.dat"
TEMPspinout="temp.spin.dat"
EQPSPINFILE="eqp.${SPINFILE}"
###############################################################
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#numofbnds=$(sed -n '1p' $INFILE | awk '{print $3}' | awk -F"," '{print $1}' )
numofbnds=$(grep -a --text 'number of Kohn-Sham states' $QEOUTPUT | awk -F "=" '{print $2}'| awk '{print $1}')
#numofkpts=$(sed -n '1p' $INFILE | awk '{print $5}')
numofkpts=$(grep -a --text 'number of k points=' $QEOUTPUT | awk -F "=" '{print $2}' | awk '{print $1}')
NumofEQPBands=$(sed -n '1p' $EIGFILE | awk '{print $4}')
echo "================================================="
NumofLines=$(wc -l $EIGFILE | awk '{print $1}')
BandStart=$(sed -n '2p' $EIGFILE | awk '{print $2}')
endline=$(echo "$NumofEQPBands+1" | bc)
BandEnd=$(sed -n "${endline} p" $EIGFILE | awk '{print $2}')
numofkpts_=$(echo ${NumofLines} ${NumofEQPBands} | awk '{print $1/($2+1)}')
######################
# Check boundaries
if [ ${numofkpts_} -ne ${numofkpts} ]; then
echo "[ERROR] Num of kpts mismatch!"
exit 1
fi
if [ ${numofbnds} -le ${NumofEQPBands} ]; then
echo "[ERROR] Num of bands from QE.out is smaller than that in eqp.dat!"
exit 1
fi
echo "========================================================"
echo "============ arrange_bands_spin.sh V.$version ============="
echo "========================================================"
echo " We are combing ${EIGFILE} and ${SPINFILE} ! "
echo " Output : ${EQPSPINFILE}"
echo "========================================================"
######################
# Number of bands in QE.out
echo "BandStart = ${BandStart} BandEnd = ${BandEnd} NumofEQPBands = ${NumofEQPBands}"
echo "Num of kpts = ${numofkpts}, Num of bands = ${numofbnds}"
echo "========================================================"
#length unit in QE
if [ -z $1 ]; then
alat=$(grep -a --text 'alat' ${QEOUTPUT} | head -1 | awk '{print $5}' )
bohrradius=0.52917721092
# transconstant=$(echo $alat $bohrradius | awk '{print $1*$2}')
transconstant=$(echo $alat $bohrradius | awk '{print $1*$2/2.0/3.14159265359}')
# echo "alat is $transconstant Angstrom"
else
transconstant=$1
# echo "alat is $transconstant Angstrom"
fi
###############################################################
####################### File clearance ######################
if [ -f $TEMPspinout ]; then
rm -f $TEMPspinout
fi
if [ -f $EQPSPINFILE ]; then
rm -f $EQPSPINFILE
fi
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
for ((ik=1;ik<=$numofkpts;ik++))
do
if [ $(echo "$ik%100" | bc) == "0" ]; then
echo "ik = ${ik}"
fi
kptline=$(echo $ik $NumofEQPBands | awk '{print ($2+1)*($1-1)+1}')
echo -e " " >> $TEMPspinout
for ((ib=$BandStart;ib<=$BandEnd;ib++))
do
lineinspinfile=$(echo ${ik} ${ib} ${numofbnds} | awk '{print ($1-1)*$3+$2+1}' )
# echo "ik = ${ik} ib = ${ib} lineinspinfile=${lineinspinfile}"
# Get the spin z component
sed -n "${lineinspinfile} p" $SPINFILE | awk '{printf("%20.12E %20.12E \n",$3,$4)}' >> $TEMPspinout
done
done
paste $EIGFILE $TEMPspinout > $EQPSPINFILE
################################################################
echo "=======================Finished!========================"