-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DFTB+ interface upgrade #179
Merged
Merged
Changes from 5 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
984c710
WIP: DFTB+ interface upgrade
danielhollas 3037dff
More cleanup
danielhollas d1408f7
Tweak CONTRIBUTING.md
danielhollas eb1bf4e
Use XYZ geometry as input
danielhollas 5742634
Add note about the dftb+ executable
danielhollas 7c285b8
Fixes
danielhollas 2768a50
Add check and output example
danielhollas 0f8a665
Merge branch 'master' into dftb-interface-cleanup
danielhollas 12596fa
README fixes
danielhollas 3a1be80
Check forces output format
danielhollas ecc7288
Fix!
danielhollas 2fff83e
Merge branch 'master' into dftb-interface-cleanup
danielhollas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,79 @@ | ||
#!/bin/bash | ||
cd $(dirname $0) | ||
source ../SetEnvironment.sh DFTB | ||
# File interface to DFTB+ program, https://dftbplus.org/ | ||
# This file typically does not need to be modified. | ||
# The input DFTB parameters are given in a file `dftb_in.hsd` in this directory, | ||
# which you need to modify for your needs. | ||
# | ||
# NOTE: This script assumes that the 'dftb+' executable is already in your PATH. | ||
# If that is not the case, modify the variable 'DFTBEXE' below accordingly. | ||
# | ||
# Tested with version 24.1. Other versions might work, but always test | ||
# by verifying energy conservation in a short NVE simulation. | ||
# Versions older than 20.1 will not work since they do not support XYZ geometry input. | ||
cd "$(dirname "$0")" || exit 2 | ||
set -u | ||
|
||
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 | ||
if [[ -f ../SetEnvironment.sh ]]; then | ||
# This is specific to Prague clusters | ||
source ../SetEnvironment.sh DFTB | ||
else | ||
# We assume dftb+ is in PATH already. If not, add it here. | ||
DFTBEXE=dftb+ | ||
fi | ||
mkdir -p $WRKDIR | ||
cd $WRKDIR | ||
|
||
# You have to specify, which elements are present in your system | ||
# i.e. define array id[x]="element" | ||
# No extra elements are allowed. | ||
awk -v natom="$natom" 'BEGIN{ | ||
id[1]="O" | ||
id[2]="H" | ||
nid=2 # number of different elements | ||
timestep="$1" | ||
ibead="$2" | ||
geom=../geom.dat."$ibead" | ||
natom=$(wc -l < "$geom") | ||
|
||
function prepare_dftb_inputs() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I created two new functions, |
||
# Working directory for the DFTB calculation | ||
WORKDIR="CALC.$ibead" | ||
rm -rf "${WORKDIR}".previous | ||
if [[ -d "$WORKDIR" ]];then | ||
mv "$WORKDIR" "${WORKDIR}".previous | ||
fi | ||
mkdir -p "$WORKDIR" | ||
|
||
# END OF USER INPUT | ||
print natom,"C" | ||
for (i=1;i<=nid;i++) { | ||
printf"%s ",id[i] | ||
} | ||
print "" | ||
print "" | ||
echo -e "$atom\n" > "$WORKDIR/geometry.xyz" | ||
cat $geom >> "$WORKDIR/geometry.xyz" | ||
|
||
cp dftb_in.hsd "$WORKDIR" | ||
# Read charge distribution from previous step if available | ||
charges_file="$WORKDIR.previous/charges.bin" | ||
if [[ -f "$charges_file" ]]; then | ||
cp "$charges_file" "$WORKDIR" | ||
sed -i 's/#ReadInitialCharges/ReadInitialCharges/' "$WORKDIR/dftb_in.hsd" | ||
fi | ||
} | ||
#conversion of xyz input to dftb geom | ||
{ | ||
for (i=1;i<=nid;i++) { | ||
if ( $1 == id[i] ) { | ||
print NR, i, $2, $3, $4 | ||
|
||
function extract_energy_and_gradients() { | ||
# Extract energy dftb+ output file | ||
dftb_out="detailed.out" | ||
engrad_file=$1 | ||
grep 'Total energy:' $dftb_out | awk '{print $3}' > $engrad_file | ||
|
||
# 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) | ||
} | ||
} | ||
} | ||
}' ../$geom > geom_in.gen | ||
}' $dftb_out >> $engrad_file | ||
} | ||
|
||
# Read initial charge distribution | ||
if [ -e charges.bin ];then | ||
sed 's/#ReadInitialCharges/ReadInitialCharges/' ../dftb_in.hsd > dftb_in.hsd | ||
else | ||
cp ../dftb_in.hsd . | ||
fi | ||
##### LET'S GO! ##### | ||
cd "$WORKDIR" || exit 2 | ||
|
||
rm -f detailed.out | ||
danielhollas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
prepare_dftb_inputs | ||
|
||
$DFTBEXE &> $input.out | ||
if [[ $? -eq 0 ]];then | ||
cp $input.out $input.out.old | ||
else | ||
echo "ERROR: DFTB calculation probably failed." | ||
echo "See $input.out.error" | ||
cp $input.out $input.out.error | ||
exit 2 | ||
$DFTBEXE &> dftb.out | ||
if [[ $? -ne 0 ]]; then | ||
echo "ERROR: DFTB calculation failed." | ||
echo "See file '$PWD/dftb.out' to find out why." | ||
exit 2 | ||
fi | ||
|
||
# Extract energy and gradients | ||
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_energy_and_gradients ../../engrad.dat."$ibead" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What should people do if they do not use the Prague clusters? Remove SetEnvironment or change it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If they are not on Prague clusters this file will simply not exist.