-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathxdat2pos.sh
91 lines (84 loc) · 3.06 KB
/
xdat2pos.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
#!/bin/bash
## written by Zhufeng HOU, Dec 14,2018
fpos='XDATCAR'
if [ $# -ne 1 ]; then
echo "Command line shall contain 1 arguments."
echo "Example: XDATCAR "
echo "1st arg: name of a XDATCAR-like file"
exit 1
else
fpos="$1"
isvasp5=false
isseldyna=false
isdirect=false
line6=`sed -n '6p' $fpos |awk '{printf "%s\n", $1}'`
line7=`sed -n '7p' $fpos |awk '{printf "%s\n", $1}'`
line8=`sed -n '8p' $fpos |awk '{printf "%s\n", $1}'`
line9=`sed -n '9p' $fpos |awk '{printf "%s\n", $1}'`
## check the 1st argument; convert the 1st character of the 1st argument into a lower case.
first_char_line6="$(printf '%s' $line6 | cut -c1)"
first_char_line7="$(printf '%s' $line7 | cut -c1)"
first_char_line8="$(printf '%s' $line8 | cut -c1)"
first_char_line9="$(printf '%s' $line9 | cut -c1)"
lfirst_char_line6=`echo "$first_char_line6" | awk '{ print tolower($1) }'`
lfirst_char_line7=`echo "$first_char_line7" | awk '{ print tolower($1) }'`
lfirst_char_line8=`echo "$first_char_line8" | awk '{ print tolower($1) }'`
lfirst_char_line9=`echo "$first_char_line9" | awk '{ print tolower($1) }'`
if [ `echo "$lfirst_char_line6" | grep [a-zA-Z]` ];then
isvasp5=true
else
isvasp5=false
fi
if $isvasp5;then
line4coor1=9
elemptype=(`sed -n '6p' $fpos`)
ionsptype=(`sed -n '7p' $fpos`)
if [ "$lfirst_char_line8" == 's' ];then
isseldyna=true
line4coor1=10
if [ "$lfirst_char_line9" == 'd' ];then
isdirect=true
fi
elif [ "$lfirst_char_line8" == 'd' ];then
isdirect=true
else
isdirect=false
isseldyna=false
fi
else
line4coor1=8
elemptype=()
ionsptype=(`sed -n '6p' $fpos`)
for index in ${!ionsptype[*]};do
elemptype+=(`echo $index |awk '{printf "%d\n", $1+1}'`)
done
if [ "$lfirst_char_line7" == 's' ];then
line4coor1=9
isseldyna=true
if [ "$lfirst_char_line8" == 'd' ];then
isdirect=true
fi
elif [ "$lfirst_char_line7" == 'd' ];then
isdirect=true
else
isdirect=false
isseldyna=false
fi
fi
#echo ${elemptype[*]} ${ionsptype[*]}
#echo $isvasp5 $isseldyna $isdirect
nions=0
for index in "${!ionsptype[@]}";do
nions=`echo 'scale=8;' "$nions + ${ionsptype[index]} "|bc -l`
done
title=`head -1 $1 | awk '{printf "%s\n", $1}'`
nconf=`grep 'configuration=' $1 |wc -l`
conflines=(`sed -n '/configuration=/=' $1 `)
titlelines=(`sed -n "/${title}/=" $1`)
for idx in `seq 0 $((${nconf}-1))`;do
idfirst=`echo 'scale=5;' "${conflines[$idx]}- ${conflines[0]} +1"|bc -l | awk '{printf "%d\n", $1}'`
idlast=`echo 'scale=5;' "$idfirst +$nions + ${conflines[0]} -1"|bc -l | awk '{printf "%d\n", $1}'`
id=`echo $idx |awk '{printf "%05d\n", $1+1}'`
sed -n "$idfirst","$idlast"p $1 > conf_"$id".vasp
done
fi