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 the start-up tasks of nwchem and return its runtime database
 * 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
 * 7) * the test for a "movecs" file as proof of convergence was removed in the scf module, since the python script may change the geometry, requiring a new run of SCF despite a valid movecs file.

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

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)

(or gcc)

I use the following script for compiling NWChem:

(on 64-bit Linux with icc)

(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: python test.py
 * 5) 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.