1#!/bin/bash
2
3#Same than in fd.in
4fd_outfile=displaced
5
6IN_DIR='./fd_files/'
7OUT_DIR='./fd_files/'
8FORCEDIR='./fd_forces/'
9pw_exe='../../../../bin/pw.x'
10
11#check directories
12if [ ! -d "${IN_DIR}" ]; then
13  echo ERROR: ${IN_DIR} does not exist
14  exit
15fi
16
17if [ ! -d "${OUT_DIR}" ]; then
18  mkdir -p ${OUT_DIR}
19fi
20
21if [ ! -d "${FORCEDIR}" ]; then
22  mkdir -p ${FORCEDIR}
23fi
24# scf calculation of the displaced macrocells
25#x,y,z displacements
26#atomic_index within original unit cell (two Si atoms)
27#positive/negative displacement
28
29for i in $(seq 1 3); do
30  for n in $(seq 1 2); do
31      for m in $(seq 1 2 ); do
32	    echo running serial pw.x on ${fd_outfile}.$m.$i.$n.in
33	    $pw_exe < $IN_DIR/${fd_outfile}.$m.$i.$n.in > $OUT_DIR/${fd_outfile}.$m.$i.$n.out;
34        done
35    done
36done
37
38# scf calculation of the reference macrocell (no displacement)
39echo running serial pw.x on ${fd_outfile}.0.0.0.in
40$pw_exe < $IN_DIR/${fd_outfile}.0.0.0.in > $OUT_DIR/${fd_outfile}.0.0.0.out
41
42# extract forces
43grep 'force =   ' $OUT_DIR/${fd_outfile}.0.0.0.out | grep '     atom ' > forces
44awk '{printf("% 18.12f % 18.12f % 18.12f \n",$7,$8,$9)}' < forces > $FORCEDIR/force.0.0.0
45rm forces
46
47for i in `seq 1 3 ` ; do
48    for n in `seq 1 2 ` ; do
49        for m in `seq 1 2 ` ; do
50            grep 'force =   ' $OUT_DIR/${fd_outfile}.$m.$i.$n.out | grep '     atom ' > forces
51            awk '{printf("% 18.12f % 18.12f % 18.12f \n",$7,$8,$9)}' < forces > $FORCEDIR/force.$m.$i.$n
52            rm forces
53        done
54    done
55done
56
57