File rdkit.spec of Package rdkit

#
# spec file for package rdkit
#
# Copyright (c) 2024 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#


%bcond_without test

%if 0%{?suse_version} > 0 && 0%{?suse_version} < 1600 && 0%{?is_opensuse}
## leap default python does not work here
%define rdk_py_ver 311
## leap 15 boost packages provide ...-devel
%define devel_impl devel
%else
%define rdk_py_ver 3
## leap 16 and tumbleweed boost packages provide ...-devel-impl
%define devel_impl devel-impl
%endif
## as boost is involved, only 1 python version can be used,
## and python_subpackages macro is not used in this spec file
%global pythons python%{rdk_py_ver}

%define pkg_rel_ver %{name}-Release_%{version}
Name:           rdkit
Version:        2024_09_5
Release:        0
Summary:        Cheminformatics and Machine-Learning Toolkit
License:        BSD-3-Clause
URL:            https://www.rdkit.org/
Source0:        https://github.com/rdkit/rdkit/archive/%{pkg_rel_ver}.tar.gz
##              https://github.com/schrodinger/maeparser/archive/v1.3.1.tar.gz
Source1:        maeparser-1.3.1.tar.gz
##              https://github.com/schrodinger/coordgenlibs/archive/v3.0.2.tar.gz
Source2:        coordgenlibs-3.0.2.tar.gz
##              https://github.com/rareylab/RingDecomposerLib/archive/v1.1.3_rdkit.tar.gz
Source3:        RingDecomposerLib-1.1.3_rdkit.tar.gz
##              https://github.com/ncbi/pubchem-align3d/archive/daefab3.tar.gz
Source4:        pubchem-align3d-daefab3.tar.gz
##              https://fonts.google.com/download?family=Comic%20Neue
Source5:        Comic_Neue.zip
##              https://github.com/Tencent/rapidjson/archive/v1.1.0.tar.gz
Source6:        rapidjson-1.1.0.tar.gz
# PATCH-FIX-UPSTREAM rapidjson.patch
Patch1:         rapidjson.patch
## support the slightly outdated boost 1.66
Patch2:         rdkit-boost-166.patch
## fix compile error w/ gcc15
Patch3:         rdkit-gcc15.patch
## fix test that failed after Catch2 upgrade
Patch4:         rdkit-catch2-39.patch
## PATCH-FIX-UPSTREAM rdkit-boost_system.patch
Patch5:         rdkit-boost_system.patch

BuildRequires:  unzip
BuildRequires:  cmake
%if 0%{?suse_version} > 0 && 0%{?suse_version} < 1600 && 0%{?is_opensuse}
BuildRequires:  gcc10-c++
%else
BuildRequires:  gcc-c++
%endif
BuildRequires:  Catch2-devel
BuildRequires:  cairo-devel
BuildRequires:  eigen3-devel
BuildRequires:  freetype2-devel
BuildRequires:  inchi-devel
BuildRequires:  %{python_module devel}
BuildRequires:  %{python_module numpy-devel}

BuildRequires:  libboost_python%{rdk_py_ver}-%{devel_impl}
BuildRequires:  libboost_numpy%{rdk_py_ver}-%{devel_impl}
BuildRequires:  libboost_iostreams-%{devel_impl}
BuildRequires:  libboost_program_options-%{devel_impl}
BuildRequires:  libboost_serialization-%{devel_impl}
%if 0%{?suse_version} > 0 && 0%{?suse_version} < 1600 && 0%{?is_opensuse}
BuildRequires:  libboost_system-%{devel_impl}
%endif

%if %{with test}
BuildRequires:  %{pythons}
BuildRequires:  %{python_module Pillow}
BuildRequires:  %{python_module cairocffi}
BuildRequires:  %{python_module pytest}
%if 0%{?suse_version} > 0 && 0%{?suse_version} < 1600 && 0%{?is_opensuse}
## leap 15 system repos do not provide pandas for pyuthon 3.11
%else
%if 0%{?suse_version} == 1600 && 0%{?is_opensuse}
## leap 16 maintainer currently refuses to provide pandas
%else
BuildRequires:  %{python_module pandas}
%endif
%endif
%endif

%description
RDKit is a collection of cheminformatics and machine-learning software
written in C++ and Python:  Core data structures and algorithms in C++;
Python 3.x wrapper generated using Boost.Python; 2D and 3D molecular
operations; Descriptor and Fingerprint generation for machine learning

%package devel
Summary:        Development Files for RDKit
Requires:       %{name} = %{version}-%{release}
Requires:       libboost_headers-%{devel_impl}
Requires:       libboost_iostreams-%{devel_impl}
Requires:       libboost_serialization-%{devel_impl}

%description devel
RDKit is a collection of cheminformatics and machine-learning software
written in C++ and Python:  Core data structures and algorithms in C++;
Python 3.x wrapper generated using Boost.Python; 2D and 3D molecular
operations; Descriptor and Fingerprint generation for machine learning

This package contains libraries, build data, and header files for
developing applications that use RDKit.

%package doc
Summary:        Documentation for RDKit

%description doc
RDKit is a collection of cheminformatics and machine-learning software
written in C++ and Python:  Core data structures and algorithms in C++;
Python 3.x wrapper generated using Boost.Python; 2D and 3D molecular
operations; Descriptor and Fingerprint generation for machine learning

This package contains documentation for RDKit.

%package -n python%{rdk_py_ver}-%{name}
Summary:        Python Bindings for RDKit Libraries
Requires:       %{name} = %{version}-%{release}
Requires:       python%{rdk_py_ver}
Requires:       python%{rdk_py_ver}-Pillow
Requires:       python%{rdk_py_ver}-cairocffi
Requires:       python%{rdk_py_ver}-numpy

%description -n python%{rdk_py_ver}-%{name}
RDKit is a collection of cheminformatics and machine-learning software
written in C++ and Python:  Core data structures and algorithms in C++;
Python 3.x wrapper generated using Boost.Python; 2D and 3D molecular
operations; Descriptor and Fingerprint generation for machine learning

This packages contains Python bindings for RDKit libraries.

%package contrib
Summary:        Contrib Files for RDKit Package
BuildArch:      noarch
Requires:       %{name} = %{version}-%{release}
Requires:       python%{rdk_py_ver}-%{name} = %{version}-%{release}

%description contrib
RDKit is a collection of cheminformatics and machine-learning software
written in C++ and Python:  Core data structures and algorithms in C++;
Python 3.x wrapper generated using Boost.Python; 2D and 3D molecular
operations; Descriptor and Fingerprint generation for machine learning

This packages contains contributed files.

%prep
%setup -q -n %{pkg_rel_ver} -b 1 -b 2 -b 3 -b 4 -b 6
%if 0%{?suse_version} > 0 && 0%{?suse_version} < 1600 && 0%{?is_opensuse}
## support the slightly outdated boost 1.66
%patch -P 2 -p1
%endif
## fix compile error w/ gcc15
%patch -P 3 -p1
## fix test that failed after Catch2 upgrade
%patch -P 4 -p1
## fix cmake files to not try to load boost_system
%if 0%{?suse_version} >= 1600 && 0%{?is_opensuse}
%patch -P 5 -p1
%endif

mv ../maeparser-1.3.1 External/CoordGen/maeparser
mv ../coordgenlibs-3.0.2 External/CoordGen/coordgen
mv ../RingDecomposerLib-1.1.3_rdkit External/RingFamilies/RingDecomposerLib
mv ../pubchem-align3d-daefab3* External/pubchem_shape/pubchem-align3d

mv ../rapidjson-1.1.0 External
%patch -P 1 -p1

pushd Data/Fonts
unzip %{SOURCE5}
popd

## SuSE only provides static libCatch2 ?!?
sed -e 's/add_library(rdkitCatch/& STATIC/' -i Code/RDGeneral/CMakeLists.txt

%if 0%{?suse_version} >= 1600
## ugly hack to make it build
##   %%cmake adds -Wl,--no-undefined to CMAKE_SHARED_LINKER_FLAGS
##   and linking against libboost_python3.so throws "undefined symbol" errors
sed -e 's/target_link_libraries(rdkit_py_base INTERFACE ${Python3_LIBRARIES}/& "python${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}"/' \
  -i CMakeLists.txt
%endif

%build
%if 0%{?suse_version} > 0 && 0%{?suse_version} < 1600 && 0%{?is_opensuse}
export CXX=g++-10
%endif
## running the tests expects an in-source build
%global __builddir .
%cmake \
   -DRDK_BUILD_INCHI_SUPPORT=ON \
   -DRDK_BUILD_CAIRO_SUPPORT=ON \
   -DRDK_INSTALL_INTREE=OFF \
   -DRDK_INSTALL_STATIC_LIBS=OFF
%cmake_build

%install
%cmake_install

## clean up python_sitearch/rdkit
pushd %{buildroot}/%{python_sitearch}/rdkit
rm -f *.{cmake,csv,svg} TestRunner.py conftest.py pytest.ini
rm -f Chem/*.cmake utils/retest.txt
rm -fr .pytest_cache Chem/nbtests sping/test
popd
## clean up _datadir/RDKit
pushd %{buildroot}/%{_datadir}/RDKit
rm -f Contrib/CMakeLists.txt
rm -f README.md
rm -f license.txt
rm -f Projects/Makefile
rm -f Projects/*.cmake
rm -fr Scripts
mv Docs/RD.css Docs/Code/Chem
popd
## fix rpmlint warnings
find %{buildroot} -name \*.py | xargs sed -e '1s,#!.*,#,' -i
rm -f %{buildroot}%{python_sitearch}/rdkit/Chem/fmcs/fmcs

%check
%if %{with test}
%if 0%{?suse_version} > 0 && 0%{?suse_version} < 1600 && 0%{?is_opensuse}
## workarounds for pythonSourceTests in leap 15
##   doctest.py chokes on fmcs.py
##   leap 15 system repos do not provide pandas for python 3.11
sed -e "s:--ignore='utils/comhack.py':& --ignore='Chem/fmcs/fmcs.py' --ignore-glob='Chem/*PandasTools.py':" \
    -i rdkit/pytest.ini
%else
%if 0%{?suse_version} == 1600 && 0%{?is_opensuse}
## workarounds for pythonSourceTests in leap 16
##   leap 16 currently does not provide pandas
sed -e "s:--ignore='utils/comhack.py':& --ignore-glob='Chem/*PandasTools.py':" \
    -i rdkit/pytest.ini
%endif
%endif
export RDBASE=%{_builddir}/%{pkg_rel_ver}
export PYTHONPATH=${RDBASE}
%ctest
%endif

%ldconfig_scriptlets

%files
%license license.txt
%doc README.md ReleaseNotes.*
%{_libdir}/lib*.so.*
%{_datadir}/RDKit/Data
%{_datadir}/RDKit/Projects

%files devel
%{_includedir}/rdkit
%{_libdir}/lib*.so
%{_libdir}/cmake/rdkit

%files doc
%docdir %{_datadir}/RDKit/Docs
%dir %{_datadir}/RDKit
%{_datadir}/RDKit/Docs

%files contrib
%{_datadir}/RDKit/Contrib

%files -n python%{rdk_py_ver}-rdkit
%{python_sitearch}/rdkit

%changelog
openSUSE Build Service is sponsored by