#!/bin/bash
#$ -S /bin/bash
#$ -N Vasp_Serial
#$ -cwd 
#$ -V
#$ -o Vasp_para.batch-log
#$ -j y
#$ -q dl165adf
#$ -pe mpi8 8


HOMEDIR=$SGE_O_WORKDIR
# No need for SCRATCHDIR

RUNNEW=run1

######################################
#
# you might have to change the following variables
#
######################################
#
# Name of the Path Input file
#
Job=Test_Vasp_Serial
#
#
# Where is Path.exe ??
#
PathExe=~/Programs/optnpath/src/Path.exe
#
# Where is VASP ?
#
export VASPDIR=~/Programs/VASP
export VASPEXEC=VASP4635_R410_STD
#
# Whre is mpirun ?
#
export MPIDIR=/softs/openmpi-1.4.1-intel/
export MPIRUN=$MPIDIR/bin/mpirun
#
#
# Machine where the files are
#
RUNNINGMACHINE=r410comp1-pub

# Some libraries... 
#
#For intel 11.1.069
source /softs/intel/v11.1.069/bin/intel64/ifortvars_intel64.sh
export LD_LIBRARY_PATH=/softs/fftw/2.1.5/ps-gb/lib:$LD_LIBRARY_PATH:/usr/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/softs/intel/v11.1.069/mkl/lib/em64t/:$MPIDIR/lib/:/softs/intel/v11.1.069/lib/intel64
export LANG=C
#
#Usually nothing has to be changed after this line
#
#################################################

#
# Machinefile
#
HOSTFILE=$TMPDIR/machines

#################################
#
# We go to the Work Directory
cd $HOMEDIR


#################################
#
#
# We check that the INCAR file is not a NEB
#
NbIm=`grep -i IMAGES INCAR  `
if [ "$NbIm" != "" ]; then
  mv INCAR INCAR.ori
  grep -v IMAGES INCAR.ori > INCAR

 echo "WARNING WARNING WARNING WARNING WARNING WARNING"
 echo "IMAGES was in INCAR "
 echo "I copied INCAR to INCAR.ori and deleted this line"
 echo "Check it !!!"
 echo "WARNING WARNING WARNING WARNING WARNING WARNING"
fi


#############################
#
#  We create the 'VaspExe' file that Path will use to run the
# actual VASP calculations of E and forces
#
#############################
cat << EOF > ./RunVasp
$MPIRUN -v -prefix $MPIDIR -mca pls_rsh_agent "ssh" -mca btl openib,self -np $NSLOTS ${VASPDIR}/${VASPEXEC} > ${HOMEDIR}/out_${RUNNEW}
EOF
chmod u+x ./RunVasp

###############################
#
# We launch PATH
#
###############################
ln -fs ${PathExe} .

./Path.exe ${Job}.path > ${Job}.out 2> ${Job}.err
 
