Index: scripts/openbabel-python2.i =================================================================== --- scripts/openbabel-python2.i (revision 0) +++ scripts/openbabel-python2.i (revision 2535) @@ -0,0 +1,92 @@ +%module obconversion + +%{ +// used to set import/export for Cygwin DLLs +#ifdef WIN32 +#define USING_OBDLL +#endif + +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +%} + +// These methods are renamed to valid Python method names, as otherwise +// they cannot be used from Python +%rename(inc) *::operator++; +%rename(good) *::operator bool; + +%import + +%import +%import +%import + +%import +%import + +%import +%import + +%include +%include +%include +%include +%import +%import +%import +%import +%import +%import +%import + +%include +%include +%include + +%include +%include + +%ignore *::operator=; + +%include "carrays.i" +%array_class(double, doubleArray) +%pythoncode %{ +def double_array(mylist): + """Create a C array of doubles from a list.""" + c = doubleArray(len(mylist)) + for i,v in enumerate(mylist): + c[i] = v + return c +%} + +# Functions to set the log file to std::cout and std::cerr + +%ignore OBForceField::SetLogFile(std::ostream *pos); +%extend OpenBabel::OBForceField { + void SetLogToStdOut() + { + self->SetLogFile(&std::cout); + } + + void SetLogToStdErr() + { + self->SetLogFile(&std::cerr); + } +}; + + Index: scripts/openbabel-python3.i =================================================================== --- scripts/openbabel-python3.i (revision 0) +++ scripts/openbabel-python3.i (revision 2535) @@ -0,0 +1,65 @@ +%module obtemplate + +%{ +// used to set import/export for Cygwin DLLs +#ifdef WIN32 +#define USING_OBDLL +#endif + +#include +#include +#include +#include +#include +#include + +%} + +%include "std_list.i" +%include "std_map.i" +%include "std_vector.i" +%include "std_string.i" + +namespace std { +%template (vectorInt) vector; +%template (vectorUnsignedInt) vector; +%template (vvInt) vector< vector >; +%template (vectorDouble) vector; +%template (vectorString) vector; +%template (vVector3) vector; + +%template (vectorMol) vector; +%template (vectorBond) vector; +%template (vectorResidue) vector; +%template (vectorRing) vector; +%template (vectorpRing) vector; +%template (vectorData) vector; +} + +// These methods are renamed to valid Python method names, as otherwise +// they cannot be used from Python +%rename(inc) *::operator++; +%rename(good) *::operator bool; + +%import + +%import +%import +%import +%import +%import +%import + +%ignore *::operator=; + +%include "carrays.i" +%array_class(double, doubleArray) +%pythoncode %{ +def double_array(mylist): + """Create a C array of doubles from a list.""" + c = doubleArray(len(mylist)) + for i,v in enumerate(mylist): + c[i] = v + return c +%} + Index: scripts/python/setup.py =================================================================== --- scripts/python/setup.py (revision 2534) +++ scripts/python/setup.py (revision 2535) @@ -60,13 +60,27 @@ OBinclude,OBlibrary = find_likely_directory() -obExtension = Extension('_openbabel', - ['openbabel_python.cpp'], - include_dirs=OBinclude, - library_dirs=OBlibrary, - libraries=['openbabel'] - ) +obCore = Extension('_obcore', + ['obcore.cpp'], + include_dirs=OBinclude, + library_dirs=OBlibrary, + libraries=['openbabel'] + ) +obConversion = Extension('_obconversion', + ['obconversion.cpp'], + include_dirs=OBinclude, + library_dirs=OBlibrary, + libraries=['openbabel'] + ) + +obTemplate = Extension('_obtemplate', + ['obtemplate.cpp'], + include_dirs=OBinclude, + library_dirs=OBlibrary, + libraries=['openbabel'] + ) + setup(name='openbabel', version='1.3', author='Noel O\'Boyle', @@ -74,7 +88,7 @@ url='http://openbabel.sourceforge.net/', license='http://www.gnu.org/copyleft/gpl.html', py_modules=['openbabel','pybel'], - ext_modules=[obExtension], + ext_modules=[obCore, obConversion, obTemplate], description = 'openbabel: Python interface to the Open Babel chemistry library', classifiers=[ 'Development Status :: 5 - Production/Stable', Index: scripts/python/openbabel.py =================================================================== --- scripts/python/openbabel.py (revision 0) +++ scripts/python/openbabel.py (revision 2535) @@ -0,0 +1,11 @@ +import sys +if sys.platform.find("linux") != -1: + try: + import dl + except ImportError: + import DLFCN as dl + sys.setdlopenflags(sys.getdlopenflags() | dl.RTLD_GLOBAL) + +import obcore +import obconversion +import obtemplate Index: scripts/Makefile.am =================================================================== --- scripts/Makefile.am (revision 2534) +++ scripts/Makefile.am (revision 2535) @@ -20,8 +20,9 @@ if MAINTAINER_MODE if BUILD_SWIG -BUILT_SOURCES = perl/openbabel_perl.cpp python/openbabel_python.cpp \ - java/openbabel_java.cpp +BUILT_SOURCES = perl/openbabel_perl.cpp \ + java/openbabel_java.cpp \ + python/obcore.cpp python/obconversion.cpp python/obtemplate.cpp script_includes = $(top_srcdir)/include/openbabel script_headers = $(script_includes)/mol.h $(script_includes)/obconversion.h \ @@ -34,20 +35,18 @@ sed -e "s/^@EXPORT.*/& sub dl_load_flags { 0x01 }/" perl/OpenBabel.new; mv perl/OpenBabel.new perl/OpenBabel.pm; -python/openbabel_python.cpp: openbabel-python.i $(script_headers) - $(SWIG) -python -modern -naturalvar -fastinit \ +python/obconversion.cpp: openbabel-python2.i $(script_headers) + $(SWIG) -small -O -python -templatereduce -naturalvar \ -c++ -o $@ -I$(top_srcdir)/include -I$(top_builddir)/include $<; - echo "import sys" >python/ob.py; - echo "if sys.platform.find(\"linux\") != -1:" >>python/ob.py; - echo " try:" >>python/ob.py; - echo " import dl" >>python/ob.py; - echo " except ImportError:" >>python/ob.py; - echo " import DLFCN as dl" >>python/ob.py; - echo " sys.setdlopenflags(sys.getdlopenflags() | dl.RTLD_GLOBAL)" >>python/ob.py; - echo >>python/ob.py; - cat python/openbabel.py >>python/ob.py; - mv python/ob.py python/openbabel.py; +python/obtemplate.cpp: openbabel-python3.i $(script_headers) + $(SWIG) -small -O -python -templatereduce -naturalvar \ + -c++ -o $@ -I$(top_srcdir)/include -I$(top_builddir)/include $<; + +python/obcore.cpp: openbabel-python.i $(script_headers) + $(SWIG) -small -O -python -templatereduce -naturalvar \ + -c++ -o $@ -I$(top_srcdir)/include -I$(top_builddir)/include $<; + java/openbabel_java.cpp: openbabel-java.i $(script_headers) $(SWIG) -java -naturalvar -c++ -o $@ -I$(top_srcdir)/include \ -I$(top_builddir)/include $<; Index: scripts/openbabel-python.i =================================================================== --- scripts/openbabel-python.i (revision 2534) +++ scripts/openbabel-python.i (revision 2535) @@ -1,4 +1,4 @@ -%module openbabel +%module obcore %{ // used to set import/export for Cygwin DLLs @@ -41,28 +41,6 @@ %} -%include "std_list.i" -%include "std_map.i" -%include "std_vector.i" -%include "std_string.i" - -namespace std { -%template (vectorInt) vector; -%template (vectorUnsignedInt) vector; -%template (vvInt) vector< vector >; -%template (vectorDouble) vector; -%template (vectorString) vector; -%template (vVector3) vector; - -%template (vectorMol) vector; -%template (vectorBond) vector; -%template (vectorResidue) vector; -%template (vectorRing) vector; -%template (vectorpRing) vector; -%template (vectorData) vector; -} - - %inline %{ OpenBabel::OBPairData *toPairData(OpenBabel::OBGenericData *data) { return (OpenBabel::OBPairData *) data; @@ -95,11 +73,11 @@ //# %import %import -%include +%import -%include -%include -%include +%import +%import +%import %include %include %include @@ -110,11 +88,11 @@ %include %include -%include -%include -%include +%import +%import +%import -%include +%import %include