Merge branch 'master' of github.com:openbabel/openbabel into ruby-reaction

This commit is contained in:
Geoff Hutchison
2026-05-14 16:36:39 -04:00
358 changed files with 132787 additions and 73276 deletions
+29 -49
View File
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 2.6.0)
# Library versioning (used in Mac Python bindings)x
cmake_minimum_required(VERSION 3.12.0)
# Library versioning (used in Mac Python bindings)
set(SOVERSION 4)
if (RUN_SWIG)
@@ -22,18 +22,8 @@ if (RUN_SWIG)
endif (RUN_SWIG)
# The following needs to be kept in synch with ..\CMakeLists.txt
if(EIGEN3_FOUND)
set (eigen_define "-DHAVE_EIGEN" "-DHAVE_EIGEN3")
include_directories(${EIGEN3_INCLUDE_DIR})
set (CPPFLAGS_VALUE "-I${EIGEN3_INCLUDE_DIR}")
set (CPPFLAGS_TEXT "CPPFLAGS=${CPPFLAGS_VALUE}")
else()
if(EIGEN2_FOUND)
set (eigen_define "-DHAVE_EIGEN")
include_directories(${EIGEN2_INCLUDE_DIR})
set (CPPFLAGS_VALUE "-I${EIGEN2_INCLUDE_DIR}")
set (CPPFLAGS_TEXT "CPPFLAGS=${CPPFLAGS_VALUE}")
endif()
if(TARGET Eigen3::Eigen)
set (eigen_define "-DHAVE_EIGEN3")
endif()
###################
@@ -42,24 +32,19 @@ endif()
if (PYTHON_BINDINGS)
if (EXISTS ${openbabel_SOURCE_DIR}/scripts/python/openbabel/openbabel-python.cpp OR RUN_SWIG)
find_package(PythonInterp)
if (NOT PYTHONINTERP_FOUND)
find_package(Python COMPONENTS Interpreter Development)
if (NOT Python_Interpreter_FOUND)
message(STATUS "Python interpreter NOT found")
endif (NOT PYTHONINTERP_FOUND)
endif (NOT Python_Interpreter_FOUND)
if (PYTHONINTERP_FOUND AND NOT Python_ADDITIONAL_VERSIONS)
set(Python_ADDITIONAL_VERSIONS "${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}")
endif (PYTHONINTERP_FOUND AND NOT Python_ADDITIONAL_VERSIONS)
find_package(PythonLibs)
if (NOT PYTHONLIBS_FOUND)
if (NOT Python_Development_FOUND)
message(STATUS "Python libraries NOT found")
endif (NOT PYTHONLIBS_FOUND)
endif (NOT Python_Development_FOUND)
if(PYTHONLIBS_FOUND AND PYTHONINTERP_FOUND)
if(Python_Development_FOUND AND Python_Interpreter_FOUND)
set(DO_PYTHON_BINDINGS ON BOOL)
message(STATUS "Python bindings will be compiled")
endif(PYTHONLIBS_FOUND AND PYTHONINTERP_FOUND)
endif(Python_Development_FOUND AND Python_Interpreter_FOUND)
else ()
message(STATUS "Warning: Python bindings NOT found. Generate using -DRUN_SWIG=ON.")
@@ -68,9 +53,9 @@ if (PYTHON_BINDINGS)
endif (PYTHON_BINDINGS)
if (DO_PYTHON_BINDINGS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
include_directories(
${PYTHON_INCLUDE_PATH}
${Python_INCLUDE_DIRS}
)
if(RUN_SWIG)
@@ -96,9 +81,9 @@ if (DO_PYTHON_BINDINGS)
else()
# Link against Python library on Linux and Windows
if(BINDINGS_ONLY)
target_link_libraries(bindings_python ${PYTHON_LIBRARIES} ${BABEL_SYSTEM_LIBRARY})
target_link_libraries(bindings_python ${Python_LIBRARIES} ${BABEL_SYSTEM_LIBRARY})
else()
target_link_libraries(bindings_python ${PYTHON_LIBRARIES} ${BABEL_LIBRARY})
target_link_libraries(bindings_python ${Python_LIBRARIES} ${BABEL_LIBRARY})
endif()
endif()
@@ -108,24 +93,14 @@ if (DO_PYTHON_BINDINGS)
PREFIX ""
LIBRARY_OUTPUT_DIRECTORY "${openbabel_SOURCE_DIR}/scripts/python/openbabel/"
SUFFIX .so )
if( "${PYTHON_INSTDIR}" STREQUAL "" )
execute_process(
COMMAND
${PYTHON_EXECUTABLE} -c "from distutils import sysconfig; print(sysconfig.get_python_lib(1,0,prefix='${CMAKE_INSTALL_PREFIX}'))"
OUTPUT_VARIABLE PYTHON_INSTDIR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
#workaround for https://bugs.launchpad.net/ubuntu/+source/python3-defaults/+bug/1814653
if(NOT ${PYTHON_INSTDIR} MATCHES "python[0-9].[0-9]")
execute_process(
COMMAND
${PYTHON_EXECUTABLE} -c "from distutils import sysconfig; print(sysconfig.get_python_lib(1,1,prefix='${CMAKE_INSTALL_PREFIX}'))"
OUTPUT_VARIABLE PYTHON_INSTDIR
OUTPUT_STRIP_TRAILING_WHITESPACE
if( "${PYTHON_INSTDIR}" STREQUAL "" )
execute_process(
COMMAND
${Python_EXECUTABLE} -c "import sysconfig; print(sysconfig.get_path('platlib', vars={'base': '${CMAKE_INSTALL_PREFIX}'}))"
OUTPUT_VARIABLE PYTHON_INSTDIR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(PYTHON_INSTDIR "${PYTHON_INSTDIR}/dist-packages")
endif()
endif()
endif()
if(NOT BINDINGS_ONLY)
add_dependencies(bindings_python openbabel)
endif()
@@ -149,7 +124,7 @@ if (DO_PYTHON_BINDINGS)
SUFFIX .pyd )
execute_process(
COMMAND
${PYTHON_EXECUTABLE} -c "from distutils import sysconfig; print(sysconfig.get_python_lib(1,0,prefix='${CMAKE_INSTALL_PREFIX}'))"
${Python_EXECUTABLE} -c "import sysconfig; print(sysconfig.get_path('platlib', vars={'base': '${CMAKE_INSTALL_PREFIX}'}))"
OUTPUT_VARIABLE PYTHON_INSTDIR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
@@ -207,6 +182,7 @@ if (JAVA_BINDINGS)
endif (JAVA_BINDINGS)
if (DO_JAVA_BINDINGS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
include_directories(
${JNI_INCLUDE_DIRS}
@@ -272,7 +248,7 @@ if (R_BINDINGS)
endif (R_BINDINGS)
if (DO_R_BINDINGS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
include_directories(/usr/share/R/include )
if (RUN_SWIG)
@@ -348,6 +324,7 @@ if (PERL_BINDINGS)
endif (PERL_BINDINGS)
if (DO_PERL_BINDINGS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
include_directories(
${PERL_INCLUDE_PATH}
)
@@ -427,6 +404,7 @@ if (DO_RUBY_BINDINGS)
)
endif (RUN_SWIG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
include_directories(
${RUBY_INCLUDE_PATH}
)
@@ -498,6 +476,7 @@ if (DO_CSHARP_BINDINGS)
)
endif (RUN_SWIG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
add_library(bindings_csharp MODULE ${openbabel_SOURCE_DIR}/scripts/csharp/openbabel-csharp.cpp)
target_link_libraries(bindings_csharp ${BABEL_LIBRARY})
set_target_properties(bindings_csharp PROPERTIES
@@ -554,6 +533,7 @@ if (PHP_BINDINGS)
endif (PHP_BINDINGS)
if (DO_PHP_BINDINGS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
include_directories(
${PHP_CONFIG_INCLUDES}
)
+2 -2
View File
@@ -63,7 +63,7 @@
%}
#ifdef HAVE_EIGEN
#ifdef HAVE_EIGEN3
%{
#include <openbabel/forcefield.h>
#include <openbabel/conformersearch.h>
@@ -364,7 +364,7 @@ IGNORE_ITER(OBMol, Residue)
%ignore OpenBabel::Swab;
%include <openbabel/rotamer.h>
%include <openbabel/spectrophore.h>
#ifdef HAVE_EIGEN
#ifdef HAVE_EIGEN3
// Ignore shadowed methods
%ignore OpenBabel::OBForceField::VectorSubtract(const double *const, const double *const, double *);
+2 -2
View File
@@ -64,7 +64,7 @@
#include <openbabel/obiter.h>
%}
#ifdef HAVE_EIGEN
#ifdef HAVE_EIGEN3
%{
#include <openbabel/conformersearch.h>
#include <openbabel/math/align.h>
@@ -304,7 +304,7 @@ IGNORE_ITER(OBMol, Residue)
%ignore OpenBabel::OBDescriptor::LessThan;
%include <openbabel/descriptor.h>
#ifdef HAVE_EIGEN
#ifdef HAVE_EIGEN3
%include <openbabel/conformersearch.h>
%include <openbabel/math/align.h>
#else
+11 -1
View File
@@ -12,6 +12,12 @@
#undef seed
#endif
// workaround perl namespace pollution - handy.h defines Zero(d,n,t) which
// conflicts with Eigen's Zero() static method declarations
#ifdef Zero
#undef Zero
#endif
#include <openbabel/obutil.h>
#include <openbabel/math/vector3.h>
#include <openbabel/math/matrix3x3.h>
@@ -214,7 +220,11 @@ namespace std { class stringbuf {}; }
// %include <openbabel/fingerprint.h> // Causes an error (I do not know why)
%include <openbabel/descriptor.h>
#ifdef HAVE_EIGEN
#ifdef HAVE_EIGEN3
%{
#include <openbabel/conformersearch.h>
#include <openbabel/math/align.h>
%}
%include <openbabel/conformersearch.h>
%include <openbabel/math/align.h>
#else
+2 -2
View File
@@ -57,7 +57,7 @@
#include <openbabel/obiter.h>
%}
#ifdef HAVE_EIGEN
#ifdef HAVE_EIGEN3
%{
#include <openbabel/conformersearch.h>
#include <openbabel/math/align.h>
@@ -281,7 +281,7 @@ IGNORE_ITER(OBMol, Residue)
%include <openbabel/rotamer.h>
%include <openbabel/spectrophore.h>
#ifdef HAVE_EIGEN
#ifdef HAVE_EIGEN3
%include <openbabel/conformersearch.h>
%include <openbabel/math/align.h>
#endif
+8 -2
View File
@@ -88,7 +88,7 @@ if sys.platform.find("linux") != -1:
%ignore OpenBabel::OBMol::FindChildren(std::vector< OBAtom * > &, OBAtom *, OBAtom *);
%ignore OpenBabel::OBResidue::GetAtoms;
#ifdef HAVE_EIGEN
#ifdef HAVE_EIGEN3
%{
#include <openbabel/conformersearch.h>
#include <openbabel/math/align.h>
@@ -356,8 +356,14 @@ OBMol.BeginResidues = OBMol.EndResidues = OBMol.BeginResidue = OBMol.EndResidue
%ignore OpenBabel::Swab;
%include <openbabel/rotamer.h>
%include <openbabel/spectrophore.h>
#ifdef HAVE_EIGEN
#ifdef HAVE_EIGEN3
// OBConformerSearch takes ownership of filter/score via SetFilter/SetScore,
// so tell SWIG to disown the Python wrapper when these are passed.
%apply SWIGTYPE *DISOWN { OpenBabel::OBConformerFilter *filter };
%apply SWIGTYPE *DISOWN { OpenBabel::OBConformerScore *score };
%include <openbabel/conformersearch.h>
%clear OpenBabel::OBConformerFilter *filter;
%clear OpenBabel::OBConformerScore *score;
%include <openbabel/math/align.h>
#endif
+1 -1
View File
@@ -243,7 +243,7 @@ namespace std { class stringbuf {}; }
// Ignore shadowed methods
%ignore OpenBabel::OBForceField::VectorSubtract(const double *const, const double *const, double *);
%ignore OpenBabel::OBForceField::VectorMultiply(const double *const, const double, double *);
#ifdef HAVE_EIGEN
#ifdef HAVE_EIGEN3
%{
#include <openbabel/conformersearch.h>
#include <openbabel/math/align.h>
+9 -7
View File
@@ -672,12 +672,13 @@ class Molecule(object):
Tkinter and Python Imaging Library are required for image display.
"""
obconversion = ob.OBConversion()
formatok = obconversion.SetOutFormat("_png2")
if not formatok:
raise ImportError("PNG depiction support not found. You should "
"compile Open Babel with support for Cairo. See "
"installation instructions for more "
"information.")
if show or filename:
formatok = obconversion.SetOutFormat("_png2")
if not formatok:
raise ImportError("PNG depiction support not found. You should "
"compile Open Babel with support for Cairo. See "
"installation instructions for more "
"information.")
# Need to copy to avoid removing hydrogens from self
workingmol = Molecule(ob.OBMol(self.OBMol))
@@ -707,7 +708,8 @@ class Molecule(object):
filedes, filename = tempfile.mkstemp()
workingmol.write("_png2", filename=filename, overwrite=True)
if show or (filedes is None):
workingmol.write("_png2", filename=filename, overwrite=True)
if show:
if sys.platform[:4] == "java":
+27 -24
View File
@@ -4,14 +4,12 @@ import os
import re
import subprocess
import sys
from distutils.command.build import build
from distutils.command.sdist import sdist
from distutils.errors import DistutilsExecError
from distutils.version import StrictVersion
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
from setuptools.command.install import install
from setuptools import setup, Extension
from setuptools.command.sdist import sdist
from setuptools.command.build import build
from packaging.version import Version
# Path to the directory that contains this setup.py file.
base_dir = os.path.abspath(os.path.dirname(__file__))
@@ -43,18 +41,18 @@ def locate_ob():
"""Try use pkgconfig to locate Open Babel, otherwise guess default location."""
try:
# Warn if the (major, minor) version of the installed OB doesn't match these python bindings
py_ver = StrictVersion(find_version())
py_major_ver, py_minor_ver = py_ver.version[:2]
pcfile = 'openbabel-{}'.format(py_major_ver)
ob_ver = StrictVersion(pkgconfig(pcfile, '--modversion'))
if not ob_ver.version[:2] == py_ver.version[:2]:
print('Warning: Open Babel {}.{}.x is required. Your version ({}) may not be compatible.'
.format(py_major_ver, py_minor_ver, ob_ver))
py_ver = Version(find_version())
py_major_ver, py_minor_ver = py_ver.release[:2]
pcfile = f'openbabel-{py_major_ver}'
ob_ver = Version(pkgconfig(pcfile, '--modversion'))
if ob_ver.release[:2] != (py_major_ver, py_minor_ver):
print(f'Warning: Open Babel {py_major_ver}.{py_minor_ver}.x is required. '
f'Your version ({ob_ver}) may not be compatible.')
include_dirs = pkgconfig(pcfile, '--variable=pkgincludedir')
library_dirs = pkgconfig(pcfile, '--variable=libdir')
print('Open Babel location automatically determined by pkg-config:')
except Exception as e:
print('Warning: %s.\nGuessing Open Babel location:' % e)
print(f'Warning: {e}.\nGuessing Open Babel location:')
include_dirs = '/usr/local/include/openbabel3'
library_dirs = '/usr/local/lib'
return include_dirs, library_dirs
@@ -64,20 +62,20 @@ class CustomBuild(build):
"""Ensure build_ext runs first in build command."""
def run(self):
self.run_command('build_ext')
build.run(self)
super().run()
class CustomInstall(install):
"""Ensure build_ext runs first in install command."""
def run(self):
self.run_command('build_ext')
install.run(self)
super().run()
class CustomSdist(sdist):
"""Add swig interface files into distribution from parent directory."""
def make_release_tree(self, base_dir, files):
sdist.make_release_tree(self, base_dir, files)
super().make_release_tree(base_dir, files)
link = 'hard' if hasattr(os, 'link') else None
pkg_dir = os.path.join(base_dir, 'openbabel')
self.copy_file(os.path.join('..', 'stereo.i'), pkg_dir, link=link)
@@ -89,7 +87,7 @@ class CustomBuildExt(build_ext):
def finalize_options(self):
# Setting include_dirs, library_dirs, swig_opts here instead of in Extension constructor allows them to be
# overridden using -I and -L command line options to python setup.py build_ext.
build_ext.finalize_options(self)
super().finalize_options()
self.ob_include_dir, self.ob_library_dir = locate_ob()
self.include_dirs.append(self.ob_include_dir)
self.library_dirs.append(self.ob_library_dir)
@@ -99,22 +97,22 @@ class CustomBuildExt(build_ext):
def swig_sources(self, sources, extension):
try:
return build_ext.swig_sources(self, sources, extension)
except DistutilsExecError:
return super().swig_sources(sources, extension)
except Exception:
print('\nError: SWIG failed. Is Open Babel installed?',
'You may need to manually specify the location of Open Babel include and library directories. '
'For example:',
' python setup.py build_ext -I{} -L{}'.format(self.ob_include_dir, self.ob_library_dir),
f' python setup.py build_ext -I{self.ob_include_dir} -L{self.ob_library_dir}',
' python setup.py install',
sep='\n')
sys.exit(1)
obextension = Extension(
'openbabel._openbabel', [os.path.join('openbabel', 'openbabel-python.i')], libraries=['openbabel']
'openbabel._openbabel', [os.path.join('openbabel', 'openbabel-python.i')],
libraries=['openbabel']
)
setup(
name='openbabel',
version=find_version(),
@@ -125,7 +123,12 @@ setup(
description='Python interface to the Open Babel chemistry library',
long_description=open(os.path.join(base_dir, 'README.rst')).read(),
zip_safe=False,
cmdclass={'build': CustomBuild, 'build_ext': CustomBuildExt, 'install': CustomInstall, 'sdist': CustomSdist},
cmdclass={
'build': CustomBuild,
'build_ext': CustomBuildExt,
'install': CustomInstall,
'sdist': CustomSdist
},
packages=['openbabel'],
ext_modules=[obextension],
classifiers=[