1#!/bin/sh 2 3# run from directory where this script is 4cd `echo $0 | sed 's/\(.*\)\/.*/\1/'` # extract pathname 5EXAMPLE_DIR=`pwd` 6 7# check whether echo has the -e option 8if test "`echo -e`" = "-e" ; then ECHO=echo ; else ECHO="echo -e" ; fi 9 10$ECHO 11$ECHO "$EXAMPLE_DIR : starting" 12$ECHO 13$ECHO "This example will calculate the initial state contribution for a Rh011 slab" 14 15# set the needed environment variables 16. ../../../environment_variables 17 18# required executables and pseudopotentials 19BIN_LIST="pw.x initial_state.x" 20PSEUDO_LIST="Rh.pbe-rrkjus_lb.UPF Rhs.pbe-rrkjus_lb.UPF" 21 22$ECHO 23$ECHO " executables directory: $BIN_DIR" 24$ECHO " pseudo directory: $PSEUDO_DIR" 25$ECHO " temporary directory: $TMP_DIR" 26$ECHO 27$ECHO " checking that needed directories and files exist...\c" 28 29# check for directories 30for DIR in "$BIN_DIR" "$PSEUDO_DIR" ; do 31 if test ! -d $DIR ; then 32 $ECHO 33 $ECHO "ERROR: $DIR not existent or not a directory" 34 $ECHO "Aborting" 35 exit 1 36 fi 37done 38for DIR in "$TMP_DIR" "$EXAMPLE_DIR/results" ; do 39 if test ! -d $DIR ; then 40 mkdir $DIR 41 fi 42done 43cd $EXAMPLE_DIR/results 44 45# check for executables 46for FILE in $BIN_LIST ; do 47 if test ! -x $BIN_DIR/$FILE ; then 48 $ECHO 49 $ECHO "ERROR: $BIN_DIR/$FILE not existent or not executable" 50 $ECHO "Aborting" 51 exit 1 52 fi 53done 54 55# check for pseudopotentials 56for FILE in $PSEUDO_LIST ; do 57 if test ! -r $PSEUDO_DIR/$FILE ; then 58 $ECHO 59 $ECHO "Downloading $FILE to $PSEUDO_DIR...\c" 60 $WGET $PSEUDO_DIR/$FILE $NETWORK_PSEUDO/$FILE 2> /dev/null 61 fi 62 if test $? != 0; then 63 $ECHO 64 $ECHO "ERROR: $PSEUDO_DIR/$FILE not existent or not readable" 65 $ECHO "Aborting" 66 exit 1 67 fi 68done 69$ECHO " done" 70 71# how to run executables 72PW_COMMAND="$PARA_PREFIX $BIN_DIR/pw.x $PARA_POSTFIX" 73IS_COMMAND="$PARA_PREFIX $BIN_DIR/initial_state.x $PARA_POSTFIX" 74$ECHO 75$ECHO " running pw.x as: $PW_COMMAND" 76$ECHO " running initial_state.x as: $IS_COMMAND" 77$ECHO 78 79# 80# self-consistent calculation. Note the definitions in ATOMIC_SPECIES and ntyp in &system 81# 82cat > rh011slab.scf.in << EOF 83 &control 84 calculation='scf', 85 restart_mode='from_scratch', 86 prefix='Rh011', 87 pseudo_dir = '$PSEUDO_DIR', 88 outdir='$TMP_DIR' 89 / 90&system 91 nat=5, ntyp=2, 92 ibrav=0, celldm(1)=10.31510000, 93 ecutwfc = 25, occupations='smearing', degauss = 0.02, smearing='mv', 94/ 95&electrons 96 mixing_beta = 0.3 97 conv_thr = 1.0d-6 98/ 99CELL_PARAMETERS alat 1000.50000000 0.00000000 0.00000000 1010.00000000 0.70710678 0.00000000 1020.00000000 0.00000000 3.00000000 103 104ATOMIC_SPECIES 105Rh 1.0 Rh.pbe-rrkjus_lb.UPF 106Rhs 1.0 Rhs.pbe-rrkjus_lb.UPF 107 108ATOMIC_POSITIONS (alat) 109 110Rh 0.25000000 0.35000000 0.50000000 111Rh 0.00000000 0.00000000 0.25000000 112Rh 0.25000000 0.35000000 0.00000000 113Rh 0.00000000 0.00000000 -0.25000000 114Rh 0.25000000 0.35000000 -0.50000000 115 116K_POINTS {gamma} 117EOF 118$ECHO 119$ECHO " running pw.x for Rh011 slab...\c" 120$PW_COMMAND < rh011slab.scf.in > rh011slab.scf.out 121check_failure $? 122$ECHO " done" 123 124# Initial state calculation as a post-processing tool 125# 126cat > rh011slab.istate.in << EOF 127&inputpp 128 prefix='Rh011', 129 outdir='$TMP_DIR' 130 excite(1) = 2, 131/ 132EOF 133$ECHO 134$ECHO " running initial_state.x for RhUS->RhsUS ...\c" 135$IS_COMMAND < rh011slab.istate.in > rh011slab.istate.out 136check_failure $? 137$ECHO " done" 138 139# 140# Extract data and write results 141# 142enbulk=$(grep "atom 3 type 1" rh011slab.istate.out | head -n1 | cut -d" " -f 19) 143enlay1=$(grep "atom 2 type 1" rh011slab.istate.out | head -n1 | cut -d" " -f 19) 144ensurf=$(grep "atom 1 type 1" rh011slab.istate.out | head -n1 | cut -d" " -f 19) 145 146 147clssurfry=$(echo "scale=5; ($enbulk)-($ensurf)" | bc) 148clssurfev=$(echo "scale=5; (($enbulk)-($ensurf))*13.6" | bc) 149 150clslay1ry=$(echo "scale=5; ($enbulk)-($enlay1)" | bc) 151clslay1ev=$(echo "scale=5; (($enbulk)-($enlay1))*13.6" | bc) 152 153$ECHO "" > initial-state.txt 154$ECHO "IS contribution for the bulk atom: $enbulk (Ry)" >> initial-state.txt 155$ECHO "IS contribution for the surface atom: $ensurf (Ry)" >> initial-state.txt 156$ECHO "IS contribution for the layer(-1) atom: $enlay1 (Ry)" >> initial-state.txt 157$ECHO "" >> initial-state.txt 158$ECHO "------------------------------------------" >> initial-state.txt 159$ECHO "" >> initial-state.txt 160$ECHO "IS shift surface: $clssurfev (eV)" >> initial-state.txt 161$ECHO "IS shift layer(-1): $clslay1ev (eV)" >> initial-state.txt 162 163$ECHO 164$ECHO " Results written in results/initial-state.txt !" 165$ECHO 166$ECHO " cleaning $TMP_DIR...\c" 167rm -rf $TMP_DIR/Rh011.* 168 169$ECHO 170$ECHO "$EXAMPLE_DIR: done" 171 172