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:

$ cd
$ mkdir bin

$ export PATH=$PATH:${HOME}/bin

Set up environment

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

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:

bash(1)

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

AJMPublic/teaching/electronic-structure/nwchem-scripts (last edited 2021-04-14 13:53:28 by apw109)