#!/bin/bash

for cell in {1..5}
do 

cell1=12.19833606051035881438  #a1*sqrt(2) +2.25%
#sqrt(2)=1.41421356237309504880
a1=8.43572239372055788  #bulk cell1
check=`echo $a1 | awk '{ printf("%20.14f\n", $1*1.41421356237309504880) }' `
#cell2rel=`echo $cell | awk '{ printf("%20.14f\n", 8.43867265607613500*1.41421356237309504880+0.1*$1) }' `
#cell2rel=`echo $cell | awk '{ printf("%20.14f\n", 12.19833606051035881438+0.1*$1) }' `
#cell2rel=`echo $cell | awk '{ printf("%20.14f\n", 12.19833606051036+0.01*$1) }' `
#cell2rel=`echo $cell | awk '{ printf("%20.14f\n", 12.18833606051036+0.001*$1) }' `
cell2rel=`echo $cell | awk '{ printf("%20.14f\n", 12.19333606051036+0.001*$1) }' `
cell3=0.45647640501156555963  #bulk c/a=0.69292474610041984035 -4.74% /cell1

mkdir $cell2rel
cd $cell2rel

cell2=`echo $cell1, $cell2rel | awk '{ printf("%20.14f\n", $2/$1) }' `

#echo $cell1
#echo $cell2rel
#echo $check
#echo $cell2
#exit -1

cat > RuO2.relax.in <<EOF
&CONTROL
 calculation='relax'
 verbosity='high'
 restart_mode='from_scratch'
 outdir='./'
 prefix='RuO2'
 pseudo_dir='./'
/
&SYSTEM
 ibrav=9
 celldm(1)=$cell1
 celldm(2)=$cell2
 celldm(3)=$cell3
 nat=6
 ntyp=2
 ecutwfc=160.0
 occupations='smearing'
 smearing='mp' 
 degauss=0.02
/
&ELECTRONS
 diagonalization='david'
 conv_thr = 1.0e-10
 diago_full_acc=.true.
 mixing_beta=0.3
/
&IONS
/
ATOMIC_SPECIES
Ru 101.07   ru.upf
O   15.9994 o.upf
ATOMIC_POSITIONS crystal
Ru       0.000000000   0.000000000   0.000000000
Ru       0.500000000   0.500000000   0.500000000
O        0.306201138   0.306201138   0.000000000
O        0.693798862   0.693798862   0.000000000
O        0.193798937   0.806201063   0.500000000
O        0.806201063   0.193798937   0.500000000
K_POINTS automatic
16 16 24 0 0 0
EOF

cp ../*upf .

cp ../jobscript_pw .
qsub jobscript_pw

cd ..

done
