-
Notifications
You must be signed in to change notification settings - Fork 2
/
cube2xyz.sh
executable file
·51 lines (41 loc) · 1.89 KB
/
cube2xyz.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
#!/bin/bash
#Extract coordinate information from a cube file (1st argument) and write to
#xyz file (2nd argument).
natoms=0
file=$1
outfile=$2
natoms=$(head -n 3 $file | tail -n 1 | awk '{print $1}')
echo -n "Found $natoms atoms..."
nlines=$((natoms+6))
if [ $outfile ] ; then
echo -n " writing to file $outfile..."
echo $natoms > $outfile
echo "xyz from $file" >> $outfile
#echo -n " doing atom: "
for i in $(seq 7 $nlines) ; do #go through each line and turn atomic numbers into elements and convert bohr to angstroem
line=$(head -n $i $file | tail -n 1)
atom=$(echo $line | awk '{print "_"$1"_"}' | sed s/_1_/H/ | sed s/_2_/He/ | sed s/_3_/Li/ | sed s/_4_/Be/ | sed s/_5_/B/ | sed s/_6_/C/ | sed s/_7_/N/ | sed s/_8_/O/ | sed s/_9_/F/ | sed s/_10_/Ne/ | sed s/_16_/S/)
x=$(echo $line | awk '{printf "% 3.8f", $3/1.889725989}')
y=$(echo $line | awk '{printf "% 3.8f", $4/1.889725989}')
z=$(echo $line | awk '{printf "% 3.8f", $5/1.889725989}')
echo -e "$atom \t $x \t $y \t $z" >> $outfile
#echo -n "$((i-6)), "
done
else
echo " no output-file given, writing to stdout:"
echo "############## XYZ file below this line #################"
echo $natoms
echo "XYZ coordinates from $file"
#echo -n " doing atom: "
for i in $(seq 7 $nlines) ; do #go through each line and turn atomic numbers into elements and convert bohr to angstroem
line=$(head -n $i $file | tail -n 1)
atom=$(echo $line | awk '{print "_"$1"_"}' | sed s/_1_/H/ | sed s/_2_/He/ | sed s/_3_/Li/ | sed s/_4_/Be/ | sed s/_5_/B/ | sed s/_6_/C/ | sed s/_7_/N/ | sed s/_8_/O/ | sed s/_9_/F/ | sed s/_10_/Ne/ | sed s/_16_/S/)
x=$(echo $line | awk '{printf "% 3.8f", $3/1.889725989}')
y=$(echo $line | awk '{printf "% 3.8f", $4/1.889725989}')
z=$(echo $line | awk '{printf "% 3.8f", $5/1.889725989}')
echo -e "$atom \t $x \t $y \t $z"
#echo -n "$((i-6)), "
done
echo " ########################################################"
fi
echo " all done!"