SEARCH
TOOLBOX
LANGUAGES
modified on 22 October 2014 at 08:39 ••• 16,599 views

Code:libnwchem

From Predictive Chemistry

Jump to: navigation, search

Libnwchem is a patch to the 6.5 Revision of NWChem that adds three useful features.

  1. 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
  2. an nwchem_init function (libnwchem.F) to perform just the start-up tasks of nwchem.F and return its runtime database handle
    • a libnwchem target to the GNUMakefile (sorry, no cygwin right now)
  3. 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

Warning: I've observed some strangeness with the test for a "movecs" file during SCF. If the python script changes the geometry, but the movecs file from a previous SCF calc. is left unchanged, SCF may be skipped. This results in similar property output for (actually) different structures.

Contents

Obtaining

You can download the patch File:Libnwchem-6.5.patch.gz. Next, get the nwchem sources from the link at the top of the page. To unpack and patch them, use

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/src
for i in Util_md_sockets Hbar Tcenxtask Parallelmpi Makefile_gcc4x Bcast_ccsd Elpa_syncs; do
  wget http://www.nwchem-sw.org/images/$i.patch.gz
  zcat $i.patch.gz | patch -p0
  rm -f $i.patch.gz
done
i=Hnd_giaxyz_noinline # there's always that one.
wget http://www.nwchem-sw.org/images/$i.patch.gz
zcat $i.patch.gz | (cd NWints/hondo && patch -p0)
rm -f $i.patch.gz
 
# Finally, apply the libnwchem patch.
zcat ../../libnwchem-6.5.patch.gz | patch -p1
cd ..
bash ../build-6.5.sh # the build-6.5.sh script is at the bottom of this page.

The mv line is really required, since nwchem's build can fail if the path to 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)

#!/bin/sh
# file $HOME/bin/icc
/opt/intel/bin/icc -fPIC $@

(or gcc)

#!/bin/sh
# file $HOME/bin/gcc
/usr/bin/gcc -fPIC $@

I use the following script for compiling NWChem:

(on 64-bit Linux with icc)

#!/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.
# (the following 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
cp util/cfileprefix.fh include/
make libnwchem

The line: cp util/cfileprefix.fh include/ is required since nwchem has a really strange way of finding dependencies that works when compiling $(MAKE) stubs.o inside nwchem's target, but doesn't work when compiling $(MAKE) stubs.o inside libnwchem's target in the same makefile!

(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,

  1. cd to nwchem-6.5/src/python
  2. export PYTHONPATH=$PWD:$PYTHONPATH
  3. 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"))
  4. run: mkdir scratch; mkdir perm
    • these two dirs are the nwchem.py default scratch and perm directories
  5. run: python test.py
  6. if all goes well, you should see normal nwchem output (listing basis functions, showing geometry convergence, and ending with a citation note)

Help

The patch is released without any warranty or indeed any guarantee of working at all. If you have lots of ($$$) around, shoot me an email.