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


PrecisionDOS=$PrecisionCommon
#PrecisionDOS=Norm
EDIFFDOS=$EDIFFCommon
EDIFFGDOS=$EDIFFGCommon
ALGODOS=$ALGOCommon
GammaOnlyDOS=$GammaOnlyCommon
aKProductDOS=$aKProductCommon
#aKProductDOS=2.0
#aKProductDOS=1.5
#aKProductDOS=fix:8/2,8/2,6/3
ISMEARDOS=$ISMEARCommon
#ISMEARDOS=-5
SIGMADOS=$SIGMACommon

NKREDDOS=$NKREDCommon
HybridALGODOS=$HybridALGOCommon
ISMEARHybridFunctionalDOS=$ISMEARHybridFunctionalCommon
SIGMAHybridFunctionalDOS=$SIGMAHybridFunctionalCommon

KeepSymmetryDOS=1

RWIGSDB=RWIGS.ini
nMesh=5000
MinEnergy=-35.0
MaxEnergy=15.0
Width=0.01

CalOpticsDOS=.TRUE.
CSHIFTDOS=0.1

LELFDOS=.TRUE.
LVTOTDOS=.FALSE.
LVHARDOS=.TRUE.

#====================================================
# DOS command
#====================================================
#MPIParamsDOS="--Param:NPAR=$NPAR --Param:KPAR=$KPAR --Param:LPLANE=.TRUE."
MPIParamsDOS=$MPIParamsCommon

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

CommonParametersDOS="--SpinOrbit=$SpinOrbit --NonCollinear=$NonCollinear --LMAXMIX=$LMAXMIX \
	--SpinPolarized=$SpinPolarized"
HFParametersDOS="--HybridFunctional=$HybridFunctional \
	--NKRED=$NKREDDOS \
	--ISMEARHybridFunctional=$ISMEARHybridFunctionalDOS \
	--SIGMAHybridFunctional=$SIGMAHybridFunctionalDOS"
PrecisionParametersDOS="--Precision=$PrecisionDOS --Param:EDIFF=$EDIFFDOS --Param:EDIFFG=$EDIFFGDOS \
	--Param:ISMEAR=$ISMEARDOS --Param:SIGMA=$SIGMADOS \
	--Param:ALGO=$ALGODOS \
	--GammaOnly=$GammaOnlyDOS --aKProduct=$aKProductDOS"

CMDDOS="$CMD --Action=ModifyFiles --Function=dos \
	$MPIParamsDOS \
	$CommonParametersDOS \
	$HFParametersDOS \
	$PrecisionParametersDOS \
	$AdditionalParametersDOS \
	--MeasreudFromEF=1 --MinEnergy=$MinEnergy --MaxEnergy=$MaxEnergy --nMesh=$nMesh \
	--KeepSymmetry=$KeepSymmetryDOS \
	--CalOptics=$CalOpticsDOS --CSHIFT=$CSHIFTDOS \
	--Param:LELF=$LELFDOS --Param:LVTOT=$LVTOTDOS --Param:LVHAR=$LVHARDOS \
	$ARG1"


#====================================
# DOS
#====================================
echo ' '
echo '================================================================'
echo "  Modify input files for DOS: [$CMDDOS]"
echo '================================================================'

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

if [ "$UseDBRWIGs" = "1" ]; then
	$CMD --Action=ChangeRWIGS --RWIGSDB=$RWIGSDB . INCAR.RWIGS
	cp INCAR INCAR.prev
	cp INCAR.RWIGS INCAR
fi



echo 
echo ======================================================================
echo vasp_modify_dos.sh finished.
echo ======================================================================
echo 
