#!/bin/bash
# use -x option for debug

#==========================================
# Prameters
#==========================================

script_dir=${0%/*}
if [ -e $script_dir/vasp_config.sh ]; then
	. $script_dir/vasp_config.sh
elif [ -e $DataRoot/scripts/vasp_config.sh ]; then
	. $DataRoot/scripts/vasp_config.sh
else
	echo 
	echo *** ERROR: Can not find [$script_dir/vasp_config.sh] nor [$DataRoot/scripts/vasp_config.sh]
	echo
	exit
fi
if [ -e $script_dir/vasp_params.sh ]; then
	. $script_dir/vasp_params.sh
fi


# For phonon, use LREAL=.FALSE. and large ENCUT like 500 eV
# For usual DFT use default for ENCUT (comment out) and LREAL=Auto
#AdditionalParameters="--Param:LREAL=Auto"
#AdditionalParameters="--Param:LREAL=Auto --Param::LWANNIER90_RUN=.FALSE."
#AdditionalParameters="--Param:LREAL=Auto --NBANDS=x2"
#AdditionalParameters="--Param:LREAL=.FALSE. --NBANDS=64 --Param:SYMPREC=1e-4";
#AdditionalParameters="--Param:LREAL=Auto --NBANDS=64 --ENCUT=500"
#AdditionalParameters="--Param:LREAL=.FALSE. --ENCUT=500"


#####???????????????#########################################
# Phonopy parameters
#####???????????????#########################################
InterfacePhonopy=VASP
#InterfacePhonopy=VASPDFPT
nSupercell="2 2 2"
MeshPoints="8 8 8"
BandPoints=51
#NonAnalyticalTermCorrection=No
NonAnalyticalTermCorrection=Yes
#fConversion=521.471
fConversion=
# phonopy irreducible representations analysis
#   the coordinate of the k point and torelance for frequency
IRREPS="0 0 0 5e-3"


PrecisionPhonopy=$PrecisionCommon
ENCUTPhonopy=500
KeepSymmetryPhonopy=$KeepSymmetry
aKProductPhonopy=$aKProductCommon
GammaOnlyPhonopy=$GammaOnlyCommon
ISMEARPhonopy=$ISMEARCommon
SIGMAPhonopy=$SIGMACommon


#====================================================
# Raman command
#====================================================
CMDRaman="$CMD --Action=ModifyFiles --Function=phonon $CommonParameters \
		--Precision=$Precision --Param:EDIFF=$EDIFF \
		--Param:NWRITE=$NWRITE --Param:NSW=$NSW \
		--KeepSymmetry=$KeepSymmetry \
		--Param:ISMEAR=$ISMEAR --Param:SIGMA=$SIGMA \
		--Param:ALGO=$ALGO \
		--SpinOrbit=$SpinOrbit --NonCollinear=$NonCollinear --LMAXMIX=$LMAXMIX \
		--GammaOnly=$GammaOnly --aKProduct=$aKProduct \
		--Pram::LEPSILON=$LEPSILON --IBRION=$IBRION \
		--FromScratch=$PhononFromScratch \
		$AdditionalParameters"

#====================================
# IR
#====================================
echo ' '
echo '================================================================'
echo "  IR run [$CalIRCMD]"
echo '================================================================'

cp $BaseDir/{hosts,*.ini} .
cp $BaseDir/{INCAR,POTCAR,POSCAR,KPOINTS,OUTCAR,WAV*,CHG*} .

$CMDIR


echo 
echo ======================================================================
echo $0 finished.
echo ======================================================================
echo 
