Skip to content

Commit

Permalink
WIP: DFTB+ interface upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhollas committed May 17, 2024
1 parent 675ae72 commit 984c710
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 18 deletions.
7 changes: 4 additions & 3 deletions interfaces/DFTB/dftb_in.hsd
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ Geometry = GenFormat {

Hamiltonian = DFTB {
SCC = Yes
MaxSCCIterations = 100
charge = 0.0
#ReadInitialCharges = yes
SlaterKosterFiles = Type2FileNames {
Prefix = "/home/hollas/3ob-2-1/"
Prefix = "/home/hollas/3ob-3-1/"
Separator = "-"
Suffix = ".skf"
}
Expand All @@ -17,8 +18,8 @@ Hamiltonian = DFTB {
}
}

Options {
CalculateForces = Yes
Analysis {
CalculateForces = Yes
}

ParserOptions {
Expand Down
55 changes: 40 additions & 15 deletions interfaces/DFTB/r.dftb
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
#!/bin/bash
# File interface to DFTB+ program, tested for version 24.1
cd $(dirname $0)
source ../SetEnvironment.sh DFTB
set -u

if [[ -f ../SetEnvironment.sh ]];then
# This is specific to Prague clusters
source ../SetEnvironment.sh DFTB
else
# We assume dftb+ is in PATH already
DFTBEXE=dftb+
fi

timestep=$1
ibead=$2
input=input$ibead
geom=../geom.dat.$ibead

natom=$(wc -l < $geom)
WRKDIR=OUT$ibead.$natom
rm -rf ${WRKDIR}.old
if [[ -d $WRKDIR ]];then
mv $WRKDIR ${WRKDIR}.old
CHARGES_FILE="charges.bin"

# Working directory for the DFTB calculation
WORKDIR=OUT$ibead.$natom
rm -rf ${WORKDIR}.previous
if [[ -d $WORKDIR ]];then
mv $WORKDIR ${WORKDIR}.previous
fi
mkdir -p $WRKDIR
cd $WRKDIR
mkdir -p $WORKDIR

# You have to specify, which elements are present in your system
# i.e. define array id[x]="element"
Expand All @@ -39,16 +50,17 @@ awk -v natom="$natom" 'BEGIN{
print NR, i, $2, $3, $4
}
}
}' ../$geom > geom_in.gen
}' $geom > $WORKDIR/geom_in.gen

# Read initial charge distribution
if [ -e charges.bin ];then
sed 's/#ReadInitialCharges/ReadInitialCharges/' ../dftb_in.hsd > dftb_in.hsd
if [[ -f $CHARGES_FILE ]]; then
cp $CHARGES_FILE $WORKDIR/
sed 's/#ReadInitialCharges/ReadInitialCharges/' dftb_in.hsd > $WORKDIR/dftb_in.hsd
else
cp ../dftb_in.hsd .
cp dftb_in.hsd $WORKDIR/
fi

rm -f detailed.out
cd $WORKDIR || exit 2

$DFTBEXE &> $input.out
if [[ $? -eq 0 ]];then
Expand All @@ -60,7 +72,20 @@ else
exit 2
fi

# Extract energy and gradients
# Extract energy
grep 'Total energy:' detailed.out | awk '{print $3}' > ../../engrad.dat.$ibead
awk -v natom=$natom '{if ($2=="Forces"){for (i=1;i<=natom;i++){getline;printf"%3.15e %3.15e %3.15e \n",-$1,-$2,-$3}}}' \
detailed.out >> ../../engrad.dat.$ibead

# Extract gradients (note the conversion from forces to gradients)
awk -v natom=$natom '{
if ($2 == "Forces") {
for (i=0; i < natom; i++) {
getline;
printf("%3.15e %3.15e %3.15e\n", -$2, -$3, -$4)
}
}
}' detailed.out >> ../../engrad.dat.$ibead

# Copy the charges for next step
if [[ -f $CHARGES_FILE ]];then
cp $CHARGES_FILE ../
fi

0 comments on commit 984c710

Please sign in to comment.