forked from ponychen123/qetools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqeout2vasp.sh
executable file
·86 lines (75 loc) · 2.54 KB
/
qeout2vasp.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
#!/bin/bash
#this script transfer the relax cell and coordination to the POSCAR
#usage: ./qeout2in.sh outputfile inputfile $1 is the output result after relaxation
#and $2 is the input file relative the output file
#the script maily used to visiualize the qe output by VESTA
#ponychen
#20190629
#email:[email protected]
#get the relaxed atomic coordinations
atombegin=`grep -in "ATOMIC_POSITIONS" $1 | tail -1 | awk ' BEGIN{FS=":"} {print $1+1}'`
atomend=`grep -in "End final coor" $1 | awk ' BEGIN{FS=":"} {print $1-1}'`
atomnum=$(($atomend-$atombegin+1))
eval $( awk -v num=$atomnum -v begin=$atombegin -v end=$atomend '
NR>=begin && NR<=end {x[NR-begin+1]=$2;y[NR-begin+1]=$3;z[NR-begin+1]=$4}
END{for(i=1;i<=num;i++){
printf("coor[%d]=\"%9.6f %9.6f %9.6f \"\n",i,x[i],y[i],z[i])}}' $1)
#get the element symbol of all atom
eval $( awk -v num=$atomnum -v begin=$atombegin -v end=$atomend '
NR>=begin && NR<=end {x[NR-begin+1]=$1;}
END{for(i=1;i<=num;i++){
printf("elements[%d]=\"%s\"\n", i,x[i])}}' $1)
#get the relaxed cell parameters if vc-relax are performed
cellbegin=`grep -in "CELL_PARAMETERS" $1 | tail -1 | awk 'BEGIN{FS=":"} {print $1+1}'`
cellend=$(($cellbegin+2))
if [ $cellbegin ];then
eval $( awk -v begin=$cellbegin '
NR>=begin && NR<=begin+2 {x[NR-begin+1]=$1;y[NR-begin+1]=$2;z[NR-begin+1]=$3}
END{for(i=1;i<=3;i++){
printf("cell[%d]=\" %9.6f %9.6f %9.6f\"\n",i,x[i],y[i],z[i])}}' $1)
else
cellbegin2=`grep -in "CELL_PARAMETERS" $2 | awk 'BEGIN{FS=":"} {print $1+1}'`
cellend2=$(($cellbegin2+2))
eval $( awk -v begin=$cellbegin2 '
NR>=begin && NR<=begin+2 {x[NR-begin+1]=$1;y[NR-begin+1]=$2;z[NR-begin+1]=$3}
END{for(i=1;i<=3;i++){
printf("cell[%d]=\" %9.6f %9.6f %9.6f\"\n",i,x[i],y[i],z[i])}}' $2)
fi
#get the element type and relative numbers in qe file
elebegin=`grep -in "ATOMIC_SPECIES" $2 | awk 'BEGIN{FS=":"} {print $1+1}'`
noempty="1"
itr=$elebegin
ini=0
until [ "$noempty" == "" ]
do
eval $(awk -v itr=$itr -v ini=$ini '
NR==itr {ns=$1}
END{printf("elespe[%d]=\"%s\"\n",ini,ns)}' $2)
noempty=${elespe[$ini]}
itr=$(($itr+1))
ini=$(($ini+1))
done
eletol=$(($ini-1))
for ((i=0;i<=$eletol;i++))
do
for j in ${elements[*]}
do
if [ "$j" == "${elespe[$i]}" ];then
elenum[$i]=$((${elenum[$i]}+1))
fi
done
done
#write to qe POSCAR
echo "generated by qeout2vasp.sh" > POSCAR
echo " 1.000000" >> POSCAR
for ((i=1;i<=3;i++))
do
echo "${cell[$i]}" >> POSCAR
done
echo ${elespe[*]} >> POSCAR
echo ${elenum[*]} >> POSCAR
echo "Cartesian" >> POSCAR
for ((i=1;i<=$atomnum;i=i+1))
do
echo "${coor[$i]}" >> POSCAR
done