The issue here is that you need to pass csd_reader.molecule on line 102 of your script a single refcode - you're actually passing it many recodes with '|' as a separator, hence the error message.
You could, for example, use split to get a list of all the recodes in that string: https://docs.python.org/2/library/stdtypes.html#str.split
Or you could look at constructing your list appropriately in the screen_substructure function so that you have single identifiers ready to pass in to csd_reader.molecule.
It appears that any python distribution you are compiling yourself is having similar difficulties with what libraries are linked against. As mentioned further up in this thread we looking into this to try to determine exactly what is going on. In the meantime, if you are able to install the pre-compiled python package for OS X available from the python website then we have found this works well.
I have reproduced your issue here with a relatively standard installation of OS X, so I don't suspect it's an issue with your installed gcc/g++ libraries.
I have asked for some developer input on this, so please be assured that we looking into the issue, although it may take a little time before we can get back to you as there's relatively little resource in the team right now as we are in holiday season.
I suspect you are indeed running into a library mis-match similar to the one observed here:
As the stackoverflow thread discusses, it is likely that the python you have compiled, or one of the packages installed after, is linking against some of the system (Apple's) python. Note that while the CSD Python API does not build against python on your system, numpy will. What is causing the crash? If you can narrow down what import command is failing, working with the required modules first such as numpy and lxml, then otool can be used on its libraries to see what they are linking to.
The use of LD_LIBRARY_PATH in your second step may be the issue - you would need DYLD_LIBRARY_PATH for Mac OS X. So another potential solution is to unistall the API and its required modules and ensure that is properly set for your own python first.
In general, we have tended to use the ready-compiled python installer rather than building manually on the system (i.e. download the 64-bit installer from https://www.python.org/downloads/release/python-2710/). You may have more luck with that.
As part of getting to know the CSD Python API and how it interacts with the CSD Python API menu of Mercury I created this simple python script.
It allows you to perform a reduced cell search on the currently viewed entry to see if there are other entries in the CSD that have similar reduced cells, in much the same way that CellCheckCSD does but in a more interactive manner. As such you could imagine loading a work-in-progress .res or .cif file into Mercury and performing this search as part of your initial investigation of the structure. The script will return the currently viewed entry as well as any hits in the CSD so that the current entry can be easily compared with the results.
To use, copy the attached cellcheck.py file to the scripts directory in your Mercury installation, or use the CSD Python API->Options menu item to add the location containing the script. It should then appear in your Scripts menu when running Mercury.
CSDHOME needs to point to the installation directory of the CSD System as a whole, not the data. So that would be:
Additional requirements for installing on Windows
When installing the CSD Python API on Windows, the installation process may require downloading and installing numpy. The numpy module has a requirement for the Microsoft C++ Compiler for Python 2.7 - if this is not present installation will fail with a message like:
error: Microsoft Visual C++ 9.0 is required (Unable to find vcvarsall.bat). Ge t it from http://aka.ms/vcpython27 ---------------------------------------- Failed building wheel for numpy
You will need to follow the link to http://aka.ms/vcpython27 and install it and then re-run the CSD Python API install.
Most of our testing on Mac OS X has been with a standard installation of Python 2.7.10. We have done some testing with Anaconda, but this has been on Linux and Windows systems.
We're currently having a look at use of the CSD Python API on Mac OS X with Anaconda to see if we can determine what your difficulties may be.