地址:https://www.jianshu.com/p/3dd71ab6c8e8
#!/bin/bash
path_file=~/bin/vasp_path.txt
case "$1" in
mv) #移动CONTCAR为POSCAR
if [[ -s CONTCAR ]]; then printf "mv CONTCAR POSCAR\n"; mv CONTCAR POSCAR; else echo 'mv Null'; exit 1; fi
;;
md) #修改INCAR内容
if [[ -n "$2" && -s INCAR ]]; then
incar=`echo $@ | cut -d ' ' -f 3-`
grep "[ ]*$2[ ]*=[ ]*" INCAR > /dev/null
if [ $? -eq 0 ]; then if [[ -z "$3" ]]; then sed -i "s/[^ ]*\([ ]*$2[ ]*=[ ]*\)/#\1/g" INCAR; else sed -i "s/[^ ]*\([ ]*$2[ ]*=[ ]*\).*/\1$incar/g" INCAR; fi
elif [[ -n "$3" ]]; then echo " $2 = $incar" >> INCAR
fi
echo "md INCAR $2 $incar"
else echo 'md Null'; exit 1
fi
;;
ig) #检测INCAR参数是否小于给定值,若小于则修改为给定值
val=(`sed -n "/$2/p" INCAR | sed "s/$2\|=//g" | awk '{print $1}'`)
num=${#val[@]}; if [[ "${val[num-1]}" -ge "$3" ]] 2> /dev/null; then echo 'ig Null'; exit 1; else $0 md $2 $3; fi
;;
kg) #检测KPOINTS参数是否小于给定值,若小于则扩大为给定值
if [[ "$2" -gt 1 ]]; then
val0=(`sed -n '4p' KPOINTS`); val[0]=${val0[0]}; val[1]=${val0[1]}; val[2]=${val0[2]}
for ((i=2;i<41;i++))
do
for ((j=0;j<3;j++))
do
value=0; if [[ "${val[j]}" -ge "$2" || "${val[j]}" -eq 1 ]]; then :; else value=1; break; fi
done
if [[ "$value" -eq 1 ]]; then for ((j=0;j<3;j++)); do if [[ "${val[j]}" -eq 1 ]]; then :; else val[j]=$[${val0[j]}*i]; fi; done; else break; fi
done
sed -i "4c ${val[0]} ${val[1]} ${val[2]}" KPOINTS
else exit 1
fi
;;
ck)
if [[ -s POTCAR ]]; then :; else $0 po pos; fi
if [[ -s POSCAR && -s INCAR && -s KPOINTS && -s POTCAR ]]; then :; else exit 1; fi
;;
su) #替换POSCAR中元素名为POTCAR顺序
if [[ -s POSCAR && -s POTCAR ]]; then
vrhfin=(`grep VRHFIN POTCAR | sed 's/[=:]//g' | awk '{print $2}'`); num=${#vrhfin[@]}; elements="0"
for ((i=0;i<num;i++))
do
elements="$elements`printf "%5s" ${vrhfin[i]}`"
done
sed -i "6c $elements" POSCAR; sed -i "6s/^.//" POSCAR
else echo 'su Null'; exit 1
fi
;;
po) #替换POTCAR中元素名为POSCAR顺序或给定顺序
eval `grep pot_path $path_file | tr -d ' '`; test -d $pot_path && {
if [[ "$2" == "pos" && -s POSCAR ]]; then
val=`sed -n 6p POSCAR`
else val=`echo $@ | cut -d ' ' -f 2-`
fi
for element in $val
do
element=(`find $pot_path -type d -name "$element*" | sort`)
if [[ -n "$element" ]]; then cat $element/POTCAR; fi
done > POTCAR; }
;;
re) #检测是否达到收敛
grep 'reached required accuracy' OUTCAR > /dev/null && pwd || { pwd && exit 1; }
;;
relax)
if [[ "$2" == "non" ]]; then ISMEAR=0; SIGMA=""; else ISMEAR=""; SIGMA=""; fi
$0 md ICHARG 2; $0 md LCHARG .FALSE.; $0 md LWAVE .TRUE.; $0 md ISTART
$0 ig NSW 100; $0 ig IBRION 1; $0 ig ISIF 3
$0 md ISMEAR $ISMEAR; $0 md SIGMA $SIGMA
;;
static)
$0 md ICHARG 2; $0 md LCHARG .TRUE.; $0 md LWAVE .TRUE.; $0 md ISTART 0
$0 md NSW; $0 md IBRION -1; $0 md EDIFFG; $0 md ISIF; $0 md POTIM
$0 md ISMEAR 0; $0 md SIGMA 0.05
;;
dos)
$0 md ICHARG 11; $0 md LCHARG .FALSE.; $0 md LWAVE .FALSE.; $0 md ISTART 0
$0 md NSW; $0 md IBRION -1; $0 md EDIFFG; $0 md ISIF; $0 md POTIM
$0 md ISMEAR 0; $0 md SIGMA 0.05
;;
*)
echo "Usage: sh.che {mv|md command parameters|ig command parameter|kg number|ck|su|po pos/elements|re|relax non|static|dos}"
;;
esac
网友评论