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 3
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: "3e3aada59bde3094ee33d609555238d6b1c5925bc90c294dec635c6cc80ac8a3"
sha256 cellar: :any, arm64_big_sur: "6505d172d6d65d33f58cf06f3e1eb7108c17e7256c8109ae0f1345d08a88fb2e"
sha256 cellar: :any, monterey: "12ea4b81ef14de55768330dc062ada65c1196e9fd168dd687cd0206e20efdab2"
sha256 cellar: :any, big_sur: "470aeb0cc56610f8a47417047198bd2d950bea88de353736d946c8b1bc9f4af3"
sha256 cellar: :any, catalina: "7dd09a04d3b9bb69bd34515772f9b4c32f189696a8796bfe58457a00ab02cbea"
sha256 cellar: :any_skip_relocation, x86_64_linux: "6acce1dfac78b50c68ec7245a5d1139a8519c3a99807505f2b6df04ea793d7af"
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