Code:libnwchem

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
 * 2) * push_inp_cstring (push_inp_cstring.c) to provide a 0-terminated c-string interface to same
 * 3) an nwchem_init function (libnwchem.F) to perform just the start-up tasks of nwchem.F and return its runtime database handle
 * 4) * a libnwchem target to the GNUMakefile (sorry, no cygwin right now)
 * 5) nwchem.py, rtdb.py and related python wrappers to call nwchem's top-level functions and handle io from the rtdb
 * 6) * 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.

Obtaining
You can download the patch. Next, get the nwchem sources from the link at the top of the page. To unpack and patch them, use

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)

(or gcc)

I use the following script for compiling NWChem:

(on 64-bit Linux with icc) 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
 * 5) * these two dirs are the nwchem.py default scratch and perm directories
 * 6) run: python test.py
 * 7) 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.