homebrew-core/Formula/rdkit.rb

118 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_09_1.tar.gz"
sha256 "a65eb24b83b7f233a134f7bc3f1823ce21162fb8c83c3d33022c05adeb5cee04"
license "BSD-3-Clause"
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: "bd3b7112ae960449be57547b0c3d6ed46dd17e8e64f84cef15cc594181e237eb"
sha256 cellar: :any, arm64_big_sur: "9f9175a707ff7bb58f87004c8aac9541dba5e0fd8113c0e883d274b8168978e3"
sha256 cellar: :any, monterey: "ae250b1706d0864d41f0c908ceb1c1e35b4cffd73acf58b453449d69f937bf69"
sha256 cellar: :any, big_sur: "c2529016b0b3d216fdaa1ada930b3fc6f87936cddc53f961b017c4d3b9175b09"
sha256 cellar: :any, catalina: "eafafca4406e83e1afd051083fdbdc80a4e0c06f8bf23775d45e6d37bca9e773"
sha256 cellar: :any_skip_relocation, x86_64_linux: "c3a9df707ad8ae7e9626cbe729eeb12ad4beb92aca46e964c5412a0b187510cf"
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