#!/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


# Set BandKPoints1=File to use *.klist file
#BandKPoints: File, XG, GY, Gz
BandKPoints=File
#BandKPoints=XG
nKPoint=51

PrecisionBand=$PrecisionCommon
#PrecisionBand=Norm
EDIFFBand=$EDIFFCommon
EDIFFGBand=$EDIFFGCommon
ALGOBand=$ALGOCommon
if [ "$HybridFunctional" != "" ]; then
	ALGOBand=$HybridALGOCommon
fi
ISMEARBand=1
#ISMEARBand=-5
SIGMABand=0.1

NELMIN=5

NKREDBand=$NKREDCommon
HybridALGOBand=$HybridALGOCommon
ISMEARHybridFunctionalBand=$ISMEARHybridFunctionalCommon
SIGMAHybridFunctionalBand=$SIGMAHybridFunctionalCommon

KeepSymmetryBand=1

CalOpticsBand=.FALSE.
SHIFTBand=0.1

LELFBand=.FALSE.

#====================================================
# Band command
#====================================================
#MPIParamsBand="--Param:NPAR=$NPAR --Param:KPAR=$KPAR --Param:LPLANE=.TRUE."
MPIParamsBand=$MPIParamsCommon

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

CommonParametersBand="--SpinOrbit=$SpinOrbit --NonCollinear=$NonCollinear --LMAXMIX=$LMAXMIX \
	--SpinPolarized=$SpinPolarized"
HFParametersBand="--HybridFunctional=$HybridFunctional \
	--NKRED=$NKREDBand \
	--ISMEARHybridFunctional=$ISMEARHybridFunctionalBand \
	--SIGMAHybridFunctional=$SIGMAHybridFunctionalBand"
PrecisionParametersBand="--Precision=$PrecisionBand --Param:EDIFF=$EDIFFBand --Param:EDIFFG=$EDIFFGBand \
	--Param:ISMEAR=$ISMEARBand --Param:SIGMA=$SIGMABand \
	--Param:ALGO=$ALGOBand \
	--GammaOnly=0 --aKProduct=$aKProductBand"

CMDBandX="$CMD --Action=ModifyFiles --Function=band \
	$MPIParamsBand \
	$CommonParametersBand \
	$HFParametersBand \
	$PrecisionParametersBand \
	$AdditionalParametersBand \
	--Param:NELMIN=$NELMIN \
	--KeepSymmetry=$KeepSymmetryBand \
	--nKPoint=$nKPoint --KPoints=$BandKPoints \
	--CalOptics=$CalOpticsBand --CSHIFT=$CSHIFTBand \
	--Param:LELF=$LELFBand \
	$ARG1"

#====================================
# Band
#====================================
echo ' '
echo '================================================================'
echo "  Modify input files for Band=[$Band1]: [$CMDBandX .]"
echo '================================================================'

if [ "$METAGGA" = "MBJ" ]; then
	cp $BaseDir/POTCAR.MBJ POTCAR
fi

$CMDBandX .
cp KPOINTS.band KPOINTS


echo 
echo ======================================================================
echo vasp_modify_band.sh finished.
echo ======================================================================
echo 
