openbabel-ruby 3.1.1.0 → 3.1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,239 @@
1
+ # Patched for CMake 4.x compatibility
2
+ cmake_minimum_required(VERSION 3.5...3.31)
3
+ # Library versioning (used in Mac Python bindings)x
4
+ set(SOVERSION 4)
5
+
6
+ if (RUN_SWIG)
7
+ include(FindSWIG)
8
+ # This module finds an installed SWIG. It sets the following variables:
9
+ # SWIG_FOUND - set to true if SWIG is found
10
+ # SWIG_DIR - the directory where swig is installed
11
+ # SWIG_EXECUTABLE - the path to the swig executable
12
+ # SWIG_VERSION - the version number of the swig executable
13
+
14
+ find_package(SWIG 2.0)
15
+ if (NOT SWIG_FOUND)
16
+ message(STATUS "SWIG 2.0 NOT found")
17
+ return()
18
+ else ()
19
+ if(SWIG_VERSION VERSION_GREATER_EQUAL 4.0)
20
+ set(doxygen_switch "-doxygen")
21
+ endif()
22
+ endif (NOT SWIG_FOUND)
23
+ endif (RUN_SWIG)
24
+
25
+ # The following needs to be kept in synch with ..\CMakeLists.txt
26
+ if(EIGEN3_FOUND)
27
+ set (eigen_define "-DHAVE_EIGEN" "-DHAVE_EIGEN3")
28
+ include_directories(${EIGEN3_INCLUDE_DIR})
29
+ set (CPPFLAGS_VALUE "-I${EIGEN3_INCLUDE_DIR}")
30
+ set (CPPFLAGS_TEXT "CPPFLAGS=${CPPFLAGS_VALUE}")
31
+ else()
32
+ if(EIGEN2_FOUND)
33
+ set (eigen_define "-DHAVE_EIGEN")
34
+ include_directories(${EIGEN2_INCLUDE_DIR})
35
+ set (CPPFLAGS_VALUE "-I${EIGEN2_INCLUDE_DIR}")
36
+ set (CPPFLAGS_TEXT "CPPFLAGS=${CPPFLAGS_VALUE}")
37
+ endif()
38
+ endif()
39
+
40
+ ###################
41
+ # Python
42
+ ###################
43
+
44
+ if (PYTHON_BINDINGS)
45
+ if (EXISTS ${openbabel_SOURCE_DIR}/scripts/python/openbabel/openbabel-python.cpp OR RUN_SWIG)
46
+ find_package(PythonInterp)
47
+ if (NOT PYTHONINTERP_FOUND)
48
+ message(STATUS "Python interpreter NOT found")
49
+ endif (NOT PYTHONINTERP_FOUND)
50
+
51
+ if (PYTHONINTERP_FOUND AND NOT Python_ADDITIONAL_VERSIONS)
52
+ set(Python_ADDITIONAL_VERSIONS "${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}")
53
+ endif (PYTHONINTERP_FOUND AND NOT Python_ADDITIONAL_VERSIONS)
54
+
55
+ find_package(PythonLibs)
56
+ if (NOT PYTHONLIBS_FOUND)
57
+ message(STATUS "Python libraries NOT found")
58
+ endif (NOT PYTHONLIBS_FOUND)
59
+
60
+ if(PYTHONLIBS_FOUND AND PYTHONINTERP_FOUND)
61
+ set(DO_PYTHON_BINDINGS ON BOOL)
62
+ message(STATUS "Python bindings will be compiled")
63
+ endif(PYTHONLIBS_FOUND AND PYTHONINTERP_FOUND)
64
+
65
+ else ()
66
+ message(STATUS "Warning: Python bindings NOT found. Generate using -DRUN_SWIG=ON.")
67
+
68
+ endif ()
69
+ endif (PYTHON_BINDINGS)
70
+
71
+ if (DO_PYTHON_BINDINGS)
72
+
73
+ include_directories(
74
+ ${PYTHON_INCLUDE_PATH}
75
+ )
76
+
77
+ if(RUN_SWIG)
78
+ add_custom_command(OUTPUT ${openbabel_SOURCE_DIR}/scripts/python/openbabel/openbabel-python.cpp ${openbabel_SOURCE_DIR}/scripts/python/openbabel/openbabel.py
79
+ COMMAND ${SWIG_EXECUTABLE} -python -c++ ${doxygen_switch} -small -O -templatereduce -naturalvar -I${openbabel_SOURCE_DIR}/include -I${openbabel_BINARY_DIR}/include -o ${openbabel_SOURCE_DIR}/scripts/python/openbabel/openbabel-python.cpp ${eigen_define} -outdir ${openbabel_SOURCE_DIR}/scripts/python/openbabel ${openbabel_SOURCE_DIR}/scripts/openbabel-python.i
80
+ MAIN_DEPENDENCY openbabel-python.i
81
+ VERBATIM
82
+ )
83
+ endif(RUN_SWIG)
84
+
85
+ configure_file(${openbabel_SOURCE_DIR}/scripts/python/openbabel/__init__.py.in
86
+ ${openbabel_SOURCE_DIR}/scripts/python/openbabel/__init__.py)
87
+ add_library(bindings_python MODULE ${openbabel_SOURCE_DIR}/scripts/python/openbabel/openbabel-python.cpp)
88
+
89
+ if(APPLE)
90
+ # Don't link against Python library on Mac
91
+ set_target_properties(bindings_python PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
92
+ if(BINDINGS_ONLY)
93
+ target_link_libraries(bindings_python ${BABEL_SYSTEM_LIBRARY})
94
+ else()
95
+ target_link_libraries(bindings_python ${BABEL_LIBRARY})
96
+ endif()
97
+ else()
98
+ # Link against Python library on Linux and Windows
99
+ if(BINDINGS_ONLY)
100
+ target_link_libraries(bindings_python ${PYTHON_LIBRARIES} ${BABEL_SYSTEM_LIBRARY})
101
+ else()
102
+ target_link_libraries(bindings_python ${PYTHON_LIBRARIES} ${BABEL_LIBRARY})
103
+ endif()
104
+ endif()
105
+
106
+ if(NOT WIN32)
107
+ set_target_properties(bindings_python PROPERTIES
108
+ OUTPUT_NAME _openbabel
109
+ PREFIX ""
110
+ LIBRARY_OUTPUT_DIRECTORY "${openbabel_SOURCE_DIR}/scripts/python/openbabel/"
111
+ SUFFIX .so )
112
+ if( "${PYTHON_INSTDIR}" STREQUAL "" )
113
+ execute_process(
114
+ COMMAND
115
+ ${PYTHON_EXECUTABLE} -c "from distutils import sysconfig; print(sysconfig.get_python_lib(1,0,prefix='${CMAKE_INSTALL_PREFIX}'))"
116
+ OUTPUT_VARIABLE PYTHON_INSTDIR
117
+ OUTPUT_STRIP_TRAILING_WHITESPACE
118
+ )
119
+ #workaround for https://bugs.launchpad.net/ubuntu/+source/python3-defaults/+bug/1814653
120
+ if(NOT ${PYTHON_INSTDIR} MATCHES "python[0-9].[0-9]")
121
+ execute_process(
122
+ COMMAND
123
+ ${PYTHON_EXECUTABLE} -c "from distutils import sysconfig; print(sysconfig.get_python_lib(1,1,prefix='${CMAKE_INSTALL_PREFIX}'))"
124
+ OUTPUT_VARIABLE PYTHON_INSTDIR
125
+ OUTPUT_STRIP_TRAILING_WHITESPACE
126
+ )
127
+ set(PYTHON_INSTDIR "${PYTHON_INSTDIR}/dist-packages")
128
+ endif()
129
+ endif()
130
+ if(NOT BINDINGS_ONLY)
131
+ add_dependencies(bindings_python openbabel)
132
+ endif()
133
+
134
+ install(TARGETS bindings_python
135
+ LIBRARY DESTINATION ${PYTHON_INSTDIR}/openbabel
136
+ COMPONENT bindings_python)
137
+ install(FILES ${openbabel_SOURCE_DIR}/scripts/python/openbabel/__init__.py
138
+ DESTINATION ${PYTHON_INSTDIR}/openbabel
139
+ COMPONENT bindings_python)
140
+ install(FILES ${openbabel_SOURCE_DIR}/scripts/python/openbabel/openbabel.py
141
+ DESTINATION ${PYTHON_INSTDIR}/openbabel
142
+ COMPONENT bindings_python)
143
+ install(FILES ${openbabel_SOURCE_DIR}/scripts/python/openbabel/pybel.py
144
+ DESTINATION ${PYTHON_INSTDIR}/openbabel
145
+ COMPONENT bindings_python)
146
+ else(NOT WIN32)
147
+ set_target_properties(bindings_python PROPERTIES
148
+ OUTPUT_NAME _openbabel
149
+ PREFIX ""
150
+ SUFFIX .pyd )
151
+ execute_process(
152
+ COMMAND
153
+ ${PYTHON_EXECUTABLE} -c "from distutils import sysconfig; print(sysconfig.get_python_lib(1,0,prefix='${CMAKE_INSTALL_PREFIX}'))"
154
+ OUTPUT_VARIABLE PYTHON_INSTDIR
155
+ OUTPUT_STRIP_TRAILING_WHITESPACE
156
+ )
157
+ if(NOT BINDINGS_ONLY)
158
+ add_dependencies(bindings_python openbabel)
159
+ endif()
160
+
161
+ install(TARGETS bindings_python
162
+ LIBRARY DESTINATION ${PYTHON_INSTDIR}/openbabel
163
+ COMPONENT bindings_python)
164
+ install(FILES ${openbabel_SOURCE_DIR}/scripts/python/openbabel/__init__.py
165
+ DESTINATION ${PYTHON_INSTDIR}/openbabel
166
+ COMPONENT bindings_python)
167
+ install(FILES ${openbabel_SOURCE_DIR}/scripts/python/openbabel/openbabel.py
168
+ DESTINATION ${PYTHON_INSTDIR}/openbabel
169
+ COMPONENT bindings_python)
170
+ install(FILES ${openbabel_SOURCE_DIR}/scripts/python/openbabel/pybel.py
171
+ DESTINATION ${PYTHON_INSTDIR}/openbabel
172
+ COMPONENT bindings_python)
173
+ add_custom_command(TARGET bindings_python POST_BUILD
174
+ COMMAND ${CMAKE_COMMAND} -E copy ${openbabel_SOURCE_DIR}/scripts/python/openbabel/openbabel.py ${openbabel_BINARY_DIR}/bin/${CMAKE_CFG_INTDIR}
175
+ )
176
+ endif(NOT WIN32)
177
+ endif (DO_PYTHON_BINDINGS)
178
+
179
+ ###################
180
+ # Ruby
181
+ ###################
182
+
183
+ if (RUBY_BINDINGS)
184
+ if (EXISTS ${openbabel_SOURCE_DIR}/scripts/ruby/openbabel-ruby.cpp OR RUN_SWIG)
185
+ find_package(Ruby)
186
+ if (NOT RUBY_LIBRARY)
187
+ message(STATUS "Ruby library files NOT found. Ruby bindings will NOT be compiled.")
188
+ endif (NOT RUBY_LIBRARY)
189
+
190
+ if (RUBY_LIBRARY)
191
+ set(DO_RUBY_BINDINGS ON BOOL)
192
+ message(STATUS "Ruby bindings will be compiled")
193
+ endif (RUBY_LIBRARY)
194
+
195
+ else (EXISTS ${openbabel_SOURCE_DIR}/scripts/ruby/openbabel-ruby.cpp OR RUN_SWIG)
196
+ message(STATUS "Warning: Ruby bindings NOT found. Generate using -DRUN_SWIG=ON.")
197
+
198
+ endif (EXISTS ${openbabel_SOURCE_DIR}/scripts/ruby/openbabel-ruby.cpp OR RUN_SWIG)
199
+ endif (RUBY_BINDINGS)
200
+
201
+ if (DO_RUBY_BINDINGS)
202
+
203
+ if (RUN_SWIG)
204
+ set(WORKAROUND_CMAKE260_BUG "s/rb_define_module(\"Openbabel\")/rb_define_module(\"OpenBabel\")/")
205
+ add_custom_command(OUTPUT ${openbabel_SOURCE_DIR}/scripts/ruby/openbabel-ruby.cpp
206
+ COMMAND ${SWIG_EXECUTABLE} -ruby -c++ -small -O -templatereduce -naturalvar -autorename -I${openbabel_SOURCE_DIR}/include -I${openbabel_BINARY_DIR}/include -o ${openbabel_SOURCE_DIR}/scripts/ruby/openbabel-ruby.txt ${openbabel_SOURCE_DIR}/scripts/openbabel-ruby.i
207
+ COMMAND sed -e '${WORKAROUND_CMAKE_260_BUG}' -e's/void Init_OpenBabel/void Init_openbabel/' <${openbabel_SOURCE_DIR}/scripts/ruby/openbabel-ruby.txt >${openbabel_SOURCE_DIR}/scripts/ruby/openbabel-ruby.cpp
208
+ COMMAND ${CMAKE_COMMAND} -E remove ${openbabel_SOURCE_DIR}/scripts/ruby/openbabel-ruby.txt
209
+ MAIN_DEPENDENCY openbabel-ruby.i
210
+ )
211
+ endif (RUN_SWIG)
212
+
213
+ include_directories(
214
+ ${RUBY_INCLUDE_PATH}
215
+ )
216
+
217
+ add_library(bindings_ruby MODULE ${openbabel_SOURCE_DIR}/scripts/ruby/openbabel-ruby.cpp)
218
+ if(BINDINGS_ONLY)
219
+ target_link_libraries(bindings_ruby ${RUBY_LIBRARY} ${BABEL_SYSTEM_LIBRARY})
220
+ else()
221
+ target_link_libraries(bindings_ruby ${RUBY_LIBRARY} ${BABEL_LIBRARY})
222
+ endif()
223
+
224
+ set_target_properties(bindings_ruby PROPERTIES
225
+ OUTPUT_NAME openbabel
226
+ PREFIX "" )
227
+
228
+ if(NOT BINDINGS_ONLY)
229
+ add_dependencies(bindings_ruby openbabel)
230
+ endif()
231
+
232
+ if( "${RUBY_INSTDIR}" STREQUAL "" )
233
+ set( RUBY_INSTDIR "${LIB_INSTALL_DIR}" )
234
+ endif()
235
+ install(TARGETS bindings_ruby
236
+ LIBRARY DESTINATION ${RUBY_INSTDIR}
237
+ COMPONENT bindings_ruby)
238
+
239
+ endif (DO_RUBY_BINDINGS)
@@ -1,4 +1,4 @@
1
1
  module OpenBabel
2
2
  VERSION = '3.1.1'
3
- GEMVERSION = VERSION + '.0'
3
+ GEMVERSION = VERSION + '.2'
4
4
  end
data/lib/openbabel.rb CHANGED
@@ -1,4 +1,83 @@
1
- require_relative '../openbabel/lib/openbabel'
1
+ # OpenBabel Ruby bindings loader
2
+ # Supports both precompiled (fat gem) and source-compiled installations
3
+
2
4
  require 'openbabel/version'
5
+
6
+ module OpenBabel
7
+ class << self
8
+ # Find the native extension directory
9
+ def find_native_extension_path
10
+ ruby_version = "#{RUBY_VERSION.split('.')[0..1].join('.')}.0"
11
+
12
+ # Check for precompiled fat gem location first
13
+ precompiled_path = File.join(__dir__, 'openbabel', ruby_version)
14
+ return precompiled_path if has_native_extension?(precompiled_path)
15
+
16
+ # Fallback to source-compiled location (relative to gem root)
17
+ source_path = File.expand_path('../openbabel/lib', __dir__)
18
+ return source_path if has_native_extension?(source_path)
19
+
20
+ # Legacy path (direct in openbabel/lib)
21
+ legacy_path = File.expand_path('../openbabel/lib/openbabel', __dir__)
22
+ return legacy_path if has_native_extension?(legacy_path)
23
+
24
+ nil
25
+ end
26
+
27
+ # Check if a directory contains the native extension
28
+ def has_native_extension?(path)
29
+ return false unless path && File.directory?(path)
30
+
31
+ # Look for .so (Linux) or .bundle (macOS)
32
+ Dir[File.join(path, 'openbabel.{so,bundle}')].any? ||
33
+ Dir[File.join(path, '*.so')].any? ||
34
+ Dir[File.join(path, '*.bundle')].any?
35
+ end
36
+
37
+ # Get the path to OpenBabel data files
38
+ def data_path
39
+ ruby_version = "#{RUBY_VERSION.split('.')[0..1].join('.')}.0"
40
+
41
+ # Check precompiled location
42
+ precompiled_data = File.join(__dir__, 'openbabel', ruby_version, 'data')
43
+ return precompiled_data if File.directory?(precompiled_data)
44
+
45
+ # Check source-compiled location
46
+ source_data = File.expand_path('../openbabel/share/openbabel', __dir__)
47
+ return source_data if File.directory?(source_data)
48
+
49
+ nil
50
+ end
51
+ end
52
+ end
53
+
54
+ # Find and load the native extension
55
+ native_path = OpenBabel.find_native_extension_path
56
+
57
+ if native_path.nil?
58
+ raise LoadError, <<~ERROR
59
+ Cannot find OpenBabel native extension.
60
+
61
+ If you installed from a precompiled gem, your Ruby version (#{RUBY_VERSION})#{' '}
62
+ may not be supported. Try installing the source gem instead:
63
+
64
+ gem install openbabel-ruby --platform ruby
65
+
66
+ If you installed from source, the compilation may have failed.
67
+ Check the installation logs for errors.
68
+ ERROR
69
+ end
70
+
71
+ # Add native path to load path
72
+ $LOAD_PATH.unshift(native_path) unless $LOAD_PATH.include?(native_path)
73
+
74
+ # Set BABEL_DATADIR environment variable if data files are bundled
75
+ data_path = OpenBabel.data_path
76
+ ENV['BABEL_DATADIR'] ||= data_path if data_path && File.directory?(data_path)
77
+
78
+ # Load the native extension
79
+ require 'openbabel'
80
+
81
+ # Initialize OpenBabel plugins
3
82
  # http://sourceforge.net/mailarchive/message.php?msg_id=31065700
4
- OpenBabel::OBConversion.new # required to load plugins
83
+ OpenBabel::OBConversion.new
metadata CHANGED
@@ -1,15 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openbabel-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.1.0
4
+ version: 3.1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - An Nguyen
8
+ autorequire:
8
9
  bindir: bin
9
10
  cert_chain: []
10
- date: 2025-12-12 00:00:00.000000000 Z
11
+ date: 2026-01-24 00:00:00.000000000 Z
11
12
  dependencies: []
12
- description: OpenBabel as a GEM
13
+ description: Ruby bindings for OpenBabel, an open-source chemical toolbox for molecular
14
+ modeling, cheminformatics, and computational chemistry. Supports 110+ molecular
15
+ file formats (SMILES, SDF, MOL2, PDB, CIF, etc.), molecular fingerprints, 2D/3D
16
+ coordinate generation, and structure manipulation. The gem compiles OpenBabel 3.1.1
17
+ from source with SWIG bindings during installation.
13
18
  email:
14
19
  - caman.nguyenthanh@gmail.com
15
20
  executables: []
@@ -19,13 +24,18 @@ extra_rdoc_files: []
19
24
  files:
20
25
  - Rakefile
21
26
  - ext/openbabel/extconf.rb
27
+ - ext/openbabel/patches/CMakeLists.txt
28
+ - ext/openbabel/patches/scripts/CMakeLists.txt
22
29
  - lib/openbabel.rb
23
30
  - lib/openbabel/version.rb
24
- - test/test_openbabel.rb
25
31
  homepage: https://github.com/CamAnNguyen/openbabel-gem
26
32
  licenses:
27
33
  - GPL-3.0
28
- metadata: {}
34
+ metadata:
35
+ source_code_uri: https://github.com/CamAnNguyen/openbabel-gem
36
+ documentation_uri: https://openbabel.org/index.html
37
+ bug_tracker_uri: https://github.com/CamAnNguyen/openbabel-gem/issues
38
+ post_install_message:
29
39
  rdoc_options: []
30
40
  require_paths:
31
41
  - lib
@@ -40,8 +50,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
40
50
  - !ruby/object:Gem::Version
41
51
  version: '0'
42
52
  requirements: []
43
- rubygems_version: 4.0.1
53
+ rubygems_version: 3.5.22
54
+ signing_key:
44
55
  specification_version: 4
45
- summary: OpenBabel!
46
- test_files:
47
- - test/test_openbabel.rb
56
+ summary: Ruby bindings for OpenBabel, the chemistry toolbox
57
+ test_files: []
@@ -1,22 +0,0 @@
1
- require 'test/unit'
2
-
3
- require 'openbabel'
4
- include OpenBabel
5
-
6
- class OBTest < Test::Unit::TestCase
7
- def test_obmol
8
- # Code from http://goo.gl/9H1LZ
9
-
10
- smi2mol = OBConversion.new
11
- smi2mol.set_in_format("smi")
12
-
13
- mol = OBMol.new
14
- smi2mol.read_string(mol, 'CC(C)CCCC(C)C1CCC2C1(CCC3C2CC=C4C3(CCC(C4)O)C)C') # cholesterol, no chirality
15
- mol.add_hydrogens
16
-
17
- assert_equal(mol.num_atoms, 74)
18
- assert_in_delta(mol.get_mol_wt, 386.65, 0.1)
19
- assert_equal(mol.get_formula, "C27H46O")
20
-
21
- end
22
- end