Code:libnwchem
Libnwchem is a patch to the 6.5 Revision of NWChem that adds three useful features.
- push_inp_string and pop_inp_string (nw_inp_from_file.F) to fake string input as input from an nwchem parameter file
- push_inp_cstring (push_inp_cstring.c) to provide a 0-terminated c-string interface to same
- an nwchem_init function (libnwchem.F) to perform the start-up tasks of nwchem and return its runtime database
- a libnwchem target to the GNUMakefile (sorry, no cygwin right now)
- nwchem.py, rtdb.py and related python wrappers to call nwchem's top-level functions and handle io from the rtdb
- various fixes to error handling in rtdb
Obtaining
You can download the patch here. Next, get the nwchem sources from the link at the top of the page. To unpack and patch them, use
<source> tar xjf Nwchem-6.5.revision26243-src.2014-09-10.tar.bz2 mv Nwchem-6.5.revision26243-src nwchem-6.5 cd nwchem-6.5 patch -p1 <../libnwchem-6.5.patch bash ../build-6.5.sh # the build-6.5.sh script is at the bottom of this page. </source> The mv line is really required, since nwchem's build can fail if the path to the source directory is too long!
Compilation
For most Linux systems (but not BSD-based OSX), the -fPIC flag is required. This is such a PITA to add to nwchem's compilation that my solution is an ugly hack. Replace the real compiler with a shell script in your $HOME/bin directory, and make sure your path has $HOME/bin in front of all other directories.
(for icc) <source lang="bash">
- !/bin/sh
- file $HOME/bin/icc
/opt/intel/bin/icc -fPIC $@ </source>
(or gcc) <source lang="bash">
- !/bin/sh
- file $HOME/bin/gcc
/usr/bin/gcc -fPIC $@ </source>
I use the following script for compiling NWChem:
(on 64-bit Linux with icc) <source lang="bash">
- !/bin/bash
- file build-6.5.sh
export NWCHEM_TOP=$HOME/build/nwchem-6.5 export NWCHEM_TARGET=LINUX64
export NWCHEM_MODULES=all
export USE_MPI=y export USE_MPIF=y export USE_MPIF4=y export MPI_LIB=/apps/openmpi/1.4.5/lib export MPI_INCLUDE=/apps/openmpi/1.4.5/include export LIBMPI="-lpthread -lmpi_f90 -lmpi_f77 -lmpi -lopen-rte -lopen-pal -lrdmacm -libverbs -lpsm_infinipath -lnuma -ldl -Wl,--export-dynamic -lnsl -lutil -lm -ldl"
export ARMCI_NETWORK=OPENIB
- export IB_INCLUDE <Location of Infiniband libraries>/include
export MSG_COMMS=MPI export CC=icc export FCC=ifort export FOPTIMIZE="-O2 -fPIC" export FFLAGS="-O2 -fPIC" export CFLAGS="-O2 -fPIC" export MKLROOT=/apps/intel/mkl
- see intel's link-line advisor for generating the next line. Use the options for single dynamic library. (this is for MKL 10.3.6 with icc 11.1)
export BLASOPT="-i8 -I$MKLROOT/include/intel64/ilp64 -I$MKLROOT/include $MKLROOT/lib/intel64/libmkl_blas95_ilp64.a $MKLROOT/lib/intel64/libmkl_lapack95_ilp64.a -Wl,--start-group $MKLROOT/lib/intel64/libmkl_intel_ilp64.a $MKLROOT/lib/intel64/libmkl_core.a $MKLROOT/lib/intel64/libmkl_sequential.a -Wl,--end-group -lpthread -lm"
- These may be helpful for compiling with CUDA, but beware - the resulting program no longer loads without cuda libraries!
- export TCE_CUDA=n
- export CUDA=$CUDA_HOME/bin/nvcc
- export CUDA_FLAGS="-arch=sm_35"
- export CUDA_INCLUDE="-I$CUDA_HOME/include"
- export CUDA_LIBS="-L$CUDA_HOME/lib64 -lcudart -lcufft"
- -L/usr/X11R6/lib -lGL -lGLU -lX11 -lXi -lXmu -lglut -lGLEW
cd $NWCHEM_TOP/src
- make realclean # These two lines let you start again (theoretically).
- find . -name dependencies -exec rm {} \; -print
make nwchem_config make nwchem
- make -B -C ddscf # in case you just changed something in the ddscf directory
make libnwchem </source>
(on 64/32 OSX with gcc)
to appear!
Testing
Inspecting the patch file, you will notice that the python wrapper was added into the src/python directory. It also includes a simple test (test.py), which opens libnwchem.so from its compiled location and does geometry optimization on a water molecule. To use it yourself,
- cd to nwchem-6.5/src/python
- export PYTHONPATH=$PWD:$PYTHONPATH
- edit nwchem.py to make sure the CDLL() command has the right path to libnwchem.so (in a pinch, just move libnwchem.so to the current dir, and change the CDLL line to CDLL("libnwchem.so"))
- run: python test.py
- if all goes well, you should see normal nwchem output (listing basis functions, showing geometry convergence, and ending with a citation note)