Skip to content

Commit

Permalink
WIP: Address review
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhollas committed Dec 2, 2023
1 parent 0eb7c26 commit 527106c
Showing 1 changed file with 40 additions and 53 deletions.
93 changes: 40 additions & 53 deletions interfaces/BAGEL-SH/r.bagel-sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

# You should't need to modify this file!
# You should't need to modify this file.
# Specification of CAS wavefunction is in file "bagel.inp"

set -u
Expand All @@ -17,8 +17,8 @@ geom="../geom.dat.$ibead"
read -t 2 -a nstate
read -t 2 -a tocalc

thresh="1.0e-8" # default value is 1.0e-8 and shouldn't be modified.
# In the case of persisting convergence errors, see the "CHECK CHONVERGENCES" section bellow
thresh_CASSCF="1.0e-8"
thresh_CASPT2="1.0e-8"

# Note that the actual filename is orbitals.archive
ORBITAL_FILE=orbitals
Expand All @@ -28,16 +28,7 @@ file_exists $geom
rm -f ../engrad.dat.$ibead ../nacm.dat ENERGY.out FORCE_*

### GENERATE BAGEL INPUT
specify_molecule "$geom" "$input.json"

if [[ -f "$ORBITAL_FILE.archive" ]]; then
# Load orbitals if the archive file exists
load_orbitals $ORBITAL_FILE $input.json
else
# Calculate HF guess if the initial orbitals are not provided via the 'orbitals.archive' file
generate_hf_orbitals $input.json
fi

#
# Determine for which state we need to calculate forces
for ((ist=0; ist<nstate; ist++))
do
Expand All @@ -51,53 +42,50 @@ do
fi
done

cat >> $input.json << EOF
{
"title" : "forces",
"export" : true,
"grads" : [
{
"title": "force",
"target": $target_state
}
],
EOF
function generate_input {

# CAS section
if [[ $method == "xms_caspt2" ]]; then
input=$1

print_cas "caspt2" "$thresh" "$maxiter_CASSCF" $input.json
print_caspt2 "true" "$thresh" "$maxiter_CASPT2" "$input.json"
specify_molecule "$geom" "$input"

elif [[ $method == "ms_caspt2" ]]; then
if [[ -f "$ORBITAL_FILE.archive" ]]; then
# Load orbitals if the archive file exists
load_orbitals $ORBITAL_FILE $input
else
# Calculate HF guess if the initial orbitals are not provided via the 'orbitals.archive' file
generate_hf_orbitals $input
fi

print_cas "caspt2" "$thresh" "$maxiter_CASSCF" $input.json
print_caspt2 "false" "$thresh" "$maxiter_CASPT2" "$input.json"
print_forces "$target_state" "$input"

# CAS section
if [[ $method == "xms_caspt2" ]]; then
print_cas "caspt2" "$thresh_CASSCF" "$maxiter_CASSCF" "$input"
print_caspt2 "true" "$thresh_CASPT2" "$maxiter_CASPT2" "$input"
elif [[ $method == "ms_caspt2" ]]; then
print_cas "caspt2" "$thresh_CASSCF" "$maxiter_CASSCF" "$input"
print_caspt2 "false" "$thresh_CASPT2" "$maxiter_CASPT2" "$input"
elif [[ $method == "sa_casscf" ]]; then

print_cas "casscf" "$thresh" "$maxiter_CASSCF" "$input.json"
print_cas "casscf" "$thresh_CASSCF" "$maxiter_CASSCF" "$input"
# Remove extra dangling comma
sed -i '$ s/,$//' "$input.json"

sed -i '$ s/,$//' "$input"
else

>&2 echo "ERROR: Unknown method ($method). Specify one of \"xms_caspt2\", \"ms_caspt2\" or \"sa_casscf\" in bagel.inp"
exit 2

fi

echo -e " }]\n }," >> $input.json

save_orbitals $ORBITAL_FILE $input.json
echo -e " }]\n }," >> $input
save_orbitals $ORBITAL_FILE $input

if [[ ! -f "initial_orbitals.molden" ]];then
print_molden "initial_orbitals.molden" $input.json
print_molden "initial_orbitals.molden" $input
else
print_molden "orbitals.molden" $input.json
print_molden "orbitals.molden" $input
fi

echo "]}" >> $input.json
echo "]}" >> $input
}

generate_input $input.json
### END OF INPUT GENERATION

### EXECUTE BAGEL
Expand All @@ -113,26 +101,25 @@ smith_error='EXCEPTION RAISED: SMITH convergence not reached'
if grep -q "$casscf_error" $input.out; then
error=true
savefile=$input.out.casscf_error.$timestep
>&2 echo "ERROR: CASSCF did not converge - let's set thresh=1.0e-7 and try again."
thresh_CASSCF="1.0e-7"
maxiter_CASSCF=600
>&2 echo "ERROR: CASSCF did not converge, trying again with thresh=$thresh_CASSCF and maxiter=$maxiter_CASSCF."
>&2 echo "See file $savefile"
cp $input.out $savefile
# TODO: This also changes thresh for CASPT2, is that a problem?
sed -i "s/\"thresh\": $thresh/\"thresh\": 1.0e-7/g" $input.json
sed -i "s/\"maxiter\": $maxiter_CASSCF/\"maxiter\": 600/" $input.json
# Run the job for the second time
generate_input "$input.json"
exec_bagel $input.json $input.out
returncode=$?
fi

if grep -q "$smith_error" $input.out; then
error=true
savefile=$input.out.caspt2_error.$timestep
>&2 echo "ERROR: CASPT2 did not convergence, trying again with looser thresh=1.0e-7 and more iterations."
thresh_CASPT2="1.0e-7"
maxiter_CASPT2=1000
>&2 echo "ERROR: CASPT2 did not converge, trying again with thresh=$thresh_CASPT2 and maxiter=$maxiter_CASPT2."
>&2 echo "See file $savefile"
cp $input.out $savefile
sed -i "s/\"thresh\": $thresh/\"thresh\": 1.0e-7/g" $input.json
sed -i "s/\"maxiter\": $maxiter_CASPT2/\"maxiter\": 1000/g" $input.json
# Run the job for the second time
generate_input "$input.json"
exec_bagel $input.json $input.out
returncode=$?
fi
Expand Down

0 comments on commit 527106c

Please sign in to comment.