<> = NWChem: Scripts = These may be useful for setting up your NWChem environment variables and cleaning up jobs. == Setting up scripts == First of all, you need to know how Linux uses scripts. A script is a bit of code that can be run. These two given here are what are called '''BASH''' scripts. They are a list of commands that you could type on the command line, but, instead, we have put them in a file and made the file '''executable'''. What do we mean by that? An executable file can be run just by typing its name on the command line - with one caveat: Linux needs to know where to find it. I suggest the following: * In your home directory create a directory '''$HOME/bin/''' ('''$HOME''' is a variable that contains the name of your home directory. Try typing: '''echo $HOME'''): {{{ $ cd $ mkdir bin }}} * We will put all executable files in '''bin/'''. * Next we will tell the bash shell that it should recognise any executable files in '''bin/'''. This is done as follows: {{{ $ export PATH=$PATH:${HOME}/bin }}} * Now all executable files in '''bin/''' will be available on the command line. But you will need to type the above command each time you log into //comanche//. This is tedious so we do one more step. Edit your '''.bashrc''' file to contain the above command. This file will be executed each time you log in, and so will the commands it contains. So, if all goes well, each time you log in, your '''PATH''' will be modified as above and all commands in '''$HOME/bin/''' will be available for you to use. == Set up environment == {{{#!wiki warning Warning I've realised that this may not work as Linux doesn't allow exported environment variables to remain after a script has exited. That is, all the variables will remain defined only while the script is running and they will be nullified once it has stopped. This is a security measure to prevent scripts from altering the shell. So rather than put the commands given below in the '''setup-nwchem.basi''' script, put them in your ${HOME}/.bashrc file. This is done as follows: }}} {{{ $ cd $ vi .bashrc }}} Go into edit (insert) mode and include the following lines at the end of the file: {{{ export NWCHEM_TOP=/home/alston/NWChem/6.1.1-ifort/ export NWCHEM_TARGET=LINUX64 export PATH=$PATH:${NWCHEM_TOP}/bin/${NWCHEM_TARGET}/ }}} Save the file (unsure how to do this? See the Vim tutorial on the previous page). And execute it using {{{ $ source .bashrc $ echo $PATH }}} Does the PATH now include the path to NWChem? Call this '''setup-nwchem.bash''' [[attachment:bash]] {{{ #!/bin/bash export NWCHEM_TOP=/home/alston/NWChem/6.1.1-ifort/ export NWCHEM_TARGET=LINUX64 export PATH=$PATH:${NWCHEM_TOP}/bin/${NWCHEM_TARGET}/ }}} Save it to file. And make the file executable as follows: {{{ $ chmod +x setup-nwchem.bash }}} Now, to set up your shell variables all you need to do is: {{{ $ ./setup-nwchem.bash }}} Check to see if it has worked by typing {{{ $ echo $NWCHEM_TOP }}} It should result in {{{ /home/alston/NWChem/6.1.1-ifort/ }}} == Cleaning after an NWChem job == NWChem creates a lot of small temporary file. To erase them this script is handy: [[attachment:bash(1)]] {{{ #!/bin/bash job=$1 rm $job.b rm $job.b^-1 rm $job.c rm $job.p rm $job.zmat rm $job.movecs rm $job.db rm $job.drv.hess rm $job.lagr }}} Save it to '''clean_nwchem.bash'''. And make it executable as before: {{{ $ chmod +x clean_nwchem.bash }}} Now say you have run a job using {{{ $ nwchem h2-sto3g.nw > h2-sto3g.out }}} you can clean up all the unnecessary files using {{{ $ ./clean_nwchem.bash h2-sto3g }}}