77 lines
4.4 KiB
Plaintext
77 lines
4.4 KiB
Plaintext
|
#!/bin/csh
|
||
|
|
||
|
# This script should not be used on its own. It should be considered a part of the runstruct_castep script.
|
||
|
# It is called using "source" as we wish to pass variables between the two scripts.
|
||
|
# Included as an extra script to prevent repetition in the main script and increase readability.
|
||
|
# Initial version: 11/08/2011. Author: Aaron Hopkinson (a.hopkinson89@gmail.com)
|
||
|
#
|
||
|
# Revision: 14/10/2011. Changed variable names to better document code. Divided energy by number of ions.
|
||
|
|
||
|
# Initially we are on run 1. The max value of this is 3, when the script is complete - either by running CASTEP
|
||
|
# twice (with either failure or success) or by succeeding on first attempt.
|
||
|
set run = 1
|
||
|
|
||
|
while ( $run < 3 )
|
||
|
# Did CASTEP finish Geometry optimisation? (We want the line number)
|
||
|
set lineno = `grep -n "Geometry optimization completed successfully." $extractfilename | sed -e 's/\([0-9]*\)\(.*\)/\1/g'`
|
||
|
|
||
|
# No. The line above could not be found.
|
||
|
if ( $lineno == "") then
|
||
|
echo `grep "BFGS: WARNING" $extractfilename`
|
||
|
echo "Please adjust the parameters in the wrap file and run the program again."
|
||
|
echo "" >! error
|
||
|
# Failure.
|
||
|
exit 1
|
||
|
endif
|
||
|
|
||
|
# Subtract 20 from line number and check the lines from then onwards for the final iteration number.
|
||
|
set lineno = `expr $lineno - 20`
|
||
|
set iterno = `tail -n +$lineno $extractfilename | grep "finished iteration" | sed -e 's/\([A-Za-z: ]*\)\([0-9]*\)\(.*\)/\2/g'`
|
||
|
# Once we know the final iteration number, subtract one from it.
|
||
|
set iterno = `expr $iterno - 1`
|
||
|
# Get line number of the second to last BFGS iteration.
|
||
|
set lineno = `grep -n -e "Starting BFGS iteration[ ]*$iterno" $extractfilename | sed -e 's/\([0-9]*\)\(.*\)/\1/g'`
|
||
|
# Now see if there was an nextra_bands error in these last two iterations.
|
||
|
set extrabands = `tail -n +$lineno $extractfilename | grep -m 1 "Recommend using nextra_bands" | sed -e 's/\([A-Za-z_ ]*\)\([0-9]*\)\(.*\)/\2/g'`
|
||
|
|
||
|
# Do we need more bands? (!= "" is a yes)
|
||
|
if ( $extrabands != "" ) then
|
||
|
# Are not in extract only mode?
|
||
|
if ( ! $?extractonly ) then
|
||
|
# If it's the end of run number 2, don't run CASTEP again. We don't want to tie up too much computer time.
|
||
|
if ( $run == 2 ) then
|
||
|
echo "Again, there are no empty bands for at least one kpoint and spin."
|
||
|
echo "CASTEP will not run again, if you wish to continue the calculation please run CASTEP again with nextra_bands = $extrabands. This can be added to the wrap file if necessary."
|
||
|
echo "" >! error
|
||
|
exit 1
|
||
|
endif
|
||
|
|
||
|
# Tell user about nextra_bands, add to .param and run CASTEP once more.
|
||
|
echo "WARNING: There are no empty bands for at least one kpoint and spin; this may slow the convergence and/or lead to an inaccurate groundstate."
|
||
|
echo "The value of nextra_bands has been set to $extrabands in the param file"
|
||
|
echo "CASTEP will restart the calculation.."
|
||
|
echo "nextra_bands = $extrabands" >>! $paramfile
|
||
|
$CMDPREFIX $CASTEPCMD $seedname
|
||
|
# End of second run.
|
||
|
set run = 2
|
||
|
else
|
||
|
# If we are in extract only mode and we need to increase nextra_kpoints, tell the user but we don't want to run CASTEP.
|
||
|
echo "There are no empty bands for at least one kpoint and spin; this may slow the convergence and/or lead to an inaccurate groundstate."
|
||
|
echo "Since this program is running in extract only mode, nothing has been done. Consider setting nextra_bands to $extrabands in the param file and run CASTEP again."
|
||
|
echo "" >! error
|
||
|
exit 1
|
||
|
endif
|
||
|
else
|
||
|
# We didn't need to increase nextra_kpoints, CASTEP didn't error and everything went well, create energy file.
|
||
|
echo "Extracting energy of the structure from CASTEP output files.."
|
||
|
set energy = `grep "BFGS: Final Enthalpy" $extractfilename | sed -e 's/BFGS: Final Enthalpy[ =]*//g' | sed -e 's/[ eV]*//g'`
|
||
|
# Find number of ions for division.
|
||
|
set noions = `grep "Total number of ions in cell" $extractfilename | sed -e 's/[ ]*Total number of ions in cell[ =]*//g'`
|
||
|
# Use bc for division, write output to file. (Scale is how many decimal places - needed for negative exponents).
|
||
|
# bc doesn't like scientific notation, change from "E" -> "*10^" - also, remove the "+" for positive exponents.
|
||
|
echo "scale = 16; $energy / $noions" | sed -e 's/E/*10^/g' | sed -e 's/+//g' | bc >! energy
|
||
|
# Set run = 3, regardless of run number. We want to exit this loop.
|
||
|
set run = 3
|
||
|
endif
|
||
|
end
|