homebrew-core/Formula/rdkit.rb

119 lines
4.2 KiB
Ruby

class Rdkit < Formula
desc "Open-source chemoinformatics library"
homepage "https://rdkit.org/"
url "https://github.com/rdkit/rdkit/archive/Release_2022_09_4.tar.gz"
sha256 "edd30682cc3031cf3f2b1a400f453629db332a1018f355cd3f7ff76b2f7f5398"
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_ventura: "39a1cc1cc12f88391340add59e810c06c0598db657afb2874218566c18131e0d"
sha256 cellar: :any, arm64_monterey: "8d6ce831dece75c0ab1d2ab15a96af26b29a056746a5edd1118a61c9939f5394"
sha256 cellar: :any, arm64_big_sur: "b06872ac2e3fb8696abfcabab8d7667f190bdfed44527aad46517b941604c7a7"
sha256 cellar: :any, ventura: "91c3f9e79d268583854e8fea17db5358e73323a552836adf825dcf514fe559e3"
sha256 cellar: :any, monterey: "8197664c7ae6bd6f08489360c23d241195f6438feeaf57f50787ababf7683cc3"
sha256 cellar: :any, big_sur: "eea55518073b422ec0715c88adde79e1fbbdf4a95db4245fe91fd6653582e43a"
sha256 cellar: :any_skip_relocation, x86_64_linux: "9d53ff9d1b47eb08ac1fbb943e31783aca0622dd9688aea9462d45c7230297d3"
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.11"
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