homebrew-core/Formula/rdkit.rb

119 lines
4.1 KiB
Ruby

class Rdkit < Formula
desc "Open-source chemoinformatics library"
homepage "https://rdkit.org/"
url "https://github.com/rdkit/rdkit/archive/Release_2022_03_5.tar.gz"
sha256 "38e6fb9f063b6132310f17e654f2c4350876f9164b0a17b49fe3df7d0555a744"
license "BSD-3-Clause"
revision 2
head "https://github.com/rdkit/rdkit.git", branch: "master"
livecheck do
url :stable
regex(/^Release[._-](\d+(?:[._]\d+)+)$/i)
strategy :git do |tags|
tags.map { |tag| tag[regex, 1]&.gsub("_", ".") }.compact
end
end
bottle do
sha256 cellar: :any, arm64_monterey: "78475e78e4bf5bcbe98afe7dea77f0b93a44de5d1bdeeec028c08e3d7d302b72"
sha256 cellar: :any, arm64_big_sur: "540f8d9291e17cd4c44b4d56bbac714e525812ac03dfd9cbbf01d73928a71088"
sha256 cellar: :any, monterey: "1034abba3684d3b859717449e23e2bad586a7e9d076432d38f39cda3bba7bc09"
sha256 cellar: :any, big_sur: "2f807f48039e21653b76a6b1374684ea30d1cf7df5fbb6d0f00eeaf18c4c3794"
sha256 cellar: :any, catalina: "15d1d7ee27e43e5a24118bf8de8e67c217d708e00fceecb727198cb851b62877"
sha256 cellar: :any_skip_relocation, x86_64_linux: "4285f2fdbb4613eba4dc8ea89887c5e25ead13fad79cf9e77242be8381db0f75"
end
depends_on "cmake" => :build
depends_on "swig" => :build
depends_on "boost"
depends_on "boost-python3"
depends_on "eigen"
depends_on "freetype"
depends_on "numpy"
depends_on "postgresql@14"
depends_on "py3cairo"
depends_on "python@3.10"
def python
deps.map(&:to_formula)
.find { |f| f.name.match?(/^python@\d\.\d+$/) }
end
# Get Python location
def python_executable
python.opt_libexec/"bin/python"
end
def postgresql
Formula["postgresql@14"]
end
def install
ENV.cxx11
ENV.libcxx
ENV.append "CFLAGS", "-Wno-parentheses -Wno-logical-op-parentheses -Wno-format"
ENV.append "CXXFLAGS", "-Wno-parentheses -Wno-logical-op-parentheses -Wno-format"
py3ver = Language::Python.major_minor_version python_executable
py3prefix = if OS.mac?
python.opt_frameworks/"Python.framework/Versions"/py3ver
else
python.opt_prefix
end
py3include = py3prefix/"include/python#{py3ver}"
site_packages = Language::Python.site_packages(python_executable)
numpy_include = Formula["numpy"].opt_prefix/site_packages/"numpy/core/include"
pg_config = postgresql.opt_bin/"pg_config"
postgresql_lib = Utils.safe_popen_read(pg_config, "--pkglibdir").chomp
postgresql_include = Utils.safe_popen_read(pg_config, "--includedir-server").chomp
# set -DMAEPARSER and COORDGEN_FORCE_BUILD=ON to avoid conflicts with some formulae i.e. open-babel
args = %W[
-DCMAKE_INSTALL_RPATH=#{lib}
-DRDK_INSTALL_INTREE=OFF
-DRDK_BUILD_SWIG_WRAPPERS=OFF
-DRDK_BUILD_AVALON_SUPPORT=ON
-DRDK_BUILD_PGSQL=ON
-DRDK_PGSQL_STATIC=ON
-DMAEPARSER_FORCE_BUILD=ON
-DCOORDGEN_FORCE_BUILD=ON
-DRDK_BUILD_INCHI_SUPPORT=ON
-DRDK_BUILD_CPP_TESTS=OFF
-DRDK_INSTALL_STATIC_LIBS=OFF
-DRDK_BUILD_CAIRO_SUPPORT=ON
-DRDK_BUILD_YAEHMOP_SUPPORT=ON
-DRDK_BUILD_FREESASA_SUPPORT=ON
-DBoost_NO_BOOST_CMAKE=ON
-DPYTHON_INCLUDE_DIR=#{py3include}
-DPYTHON_EXECUTABLE=#{python_executable}
-DPYTHON_NUMPY_INCLUDE_PATH=#{numpy_include}
-DPostgreSQL_LIBRARY=#{postgresql_lib}
-DPostgreSQL_INCLUDE_DIR=#{postgresql_include}
]
system "cmake", "-S", ".", "-B", "build", *args, *std_cmake_args
system "cmake", "--build", "build"
system "cmake", "--install", "build"
(prefix/site_packages/"homebrew-rdkit.pth").write libexec/site_packages
end
def caveats
<<~EOS
You may need to add RDBASE to your environment variables.
For Bash, put something like this in your $HOME/.bashrc:
export RDBASE=#{opt_share}/RDKit
EOS
end
test do
system python_executable, "-c", "import rdkit"
(testpath/"test.py").write <<~EOS
from rdkit import Chem ; print(Chem.MolToSmiles(Chem.MolFromSmiles('C1=CC=CN=C1')))
EOS
assert_match "c1ccncc1", shell_output("#{python_executable} test.py 2>&1")
end
end