-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rdkit4coot 2024.09.1 (new formula) (#1940)
- Loading branch information
1 parent
7d5cfbf
commit fd98eca
Showing
1 changed file
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
class Rdkit4coot < Formula | ||
desc "Open-source chemoinformatics library" | ||
homepage "https://rdkit.org/" | ||
# NOTE: Make sure to update RPATHs if any "@rpath-referenced libraries" show up in `brew linkage` | ||
url "https://github.com/rdkit/rdkit/archive/refs/tags/Release_2024_09_1.tar.gz" | ||
sha256 "034c00d6e9de323506834da03400761ed8c3721095114369d06805409747a60f" | ||
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.filter_map { |tag| tag[regex, 1]&.tr("_", ".") } | ||
end | ||
end | ||
|
||
keg_only "provided by Homebrew core" | ||
|
||
depends_on "catch2" => :build | ||
depends_on "cmake" => :build | ||
depends_on "pkg-config" => :build | ||
depends_on "postgresql@14" => [:build, :test] | ||
depends_on "postgresql@17" => [:build, :test] | ||
depends_on "boost" | ||
depends_on "boost-python3" | ||
depends_on "cairo" | ||
depends_on "eigen" | ||
depends_on "freetype" | ||
depends_on "inchi" | ||
depends_on "maeparser" | ||
depends_on "numpy" | ||
depends_on "py3cairo" | ||
depends_on "[email protected]" | ||
|
||
conflicts_with "rdkit", because: "both install the same files" | ||
|
||
patch do | ||
url "https://github.com/rdkit/rdkit/commit/3ade0f8cd31be54fc267b9f5e94e8aa755f56f36.patch?full_index=1" | ||
sha256 "09696dc4c26832f5c5126d059ae0d71a12ab404438e55e8f9a90880a1fad6c03" | ||
end | ||
|
||
def python3 | ||
"python3.12" | ||
end | ||
|
||
def postgresqls | ||
deps.filter_map { |f| f.to_formula if f.name.start_with?("postgresql@") } | ||
.sort_by(&:version) | ||
end | ||
|
||
def install | ||
python_rpath = rpath(source: lib/Language::Python.site_packages(python3)) | ||
python_rpaths = [python_rpath, "#{python_rpath}/..", "#{python_rpath}/../.."] | ||
args = %W[ | ||
-DCMAKE_INSTALL_RPATH=#{rpath} | ||
-DCMAKE_MODULE_LINKER_FLAGS=#{python_rpaths.map { |path| "-Wl,-rpath,#{path}" }.join(" ")} | ||
-DCOORDGEN_FORCE_BUILD=ON | ||
-DCMAKE_REQUIRE_FIND_PACKAGE_maeparser=ON | ||
-DCMAKE_REQUIRE_FIND_PACKAGE_Inchi=ON | ||
-DINCHI_INCLUDE_DIR=#{Formula["inchi"].opt_include}/inchi | ||
-DRDK_INSTALL_INTREE=OFF | ||
-DRDK_BUILD_SWIG_WRAPPERS=OFF | ||
-DRDK_BUILD_AVALON_SUPPORT=ON | ||
-DRDK_PGSQL_STATIC=OFF | ||
-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 | ||
-DPython3_EXECUTABLE=#{which(python3)} | ||
] | ||
if build.bottle? && Hardware::CPU.intel? && (!OS.mac? || !MacOS.version.requires_sse42?) | ||
args << "-DRDK_OPTIMIZE_POPCNT=OFF" | ||
end | ||
system "cmake", "-S", ".", "-B", "build", "-DRDK_BUILD_PGSQL=OFF", *args, *std_cmake_args | ||
system "cmake", "--build", "build" | ||
system "cmake", "--install", "build" | ||
|
||
inreplace "Code/PgSQL/rdkit/CMakeLists.txt" do |s| | ||
# Prevent trying to install into pg_config-defined dirs | ||
s.sub! "set(PG_PKGLIBDIR \"${PG_PKGLIBDIR}", "set(PG_PKGLIBDIR \"$ENV{PG_PKGLIBDIR}" | ||
s.sub! "set(PG_EXTENSIONDIR \"${PG_SHAREDIR}", "set(PG_EXTENSIONDIR \"$ENV{PG_SHAREDIR}" | ||
# Re-use installed libraries when building modules for other PostgreSQL versions | ||
s.sub!(/^find_package\(PostgreSQL/, "find_package(Cairo REQUIRED)\nfind_package(rdkit REQUIRED)\n\\0") | ||
s.sub! 'set(pgRDKitLibs "${pgRDKitLibs}${pgRDKitLib}', 'set(pgRDKitLibs "${pgRDKitLibs}RDKit::${pgRDKitLib}' | ||
s.sub! ";${INCHI_LIBRARIES};", ";" | ||
# Add RPATH for PostgreSQL cartridge | ||
s.sub! '"-Wl,-dead_strip_dylibs ', "\\0-Wl,-rpath,#{loader_path}/.. " | ||
end | ||
ENV["DESTDIR"] = "/" # to force creation of non-standard PostgreSQL directories | ||
|
||
postgresqls.each do |postgresql| | ||
ENV["PG_PKGLIBDIR"] = lib/postgresql.name | ||
ENV["PG_SHAREDIR"] = share/postgresql.name | ||
builddir = "build_pg#{postgresql.version.major}" | ||
|
||
system "cmake", "-S", ".", "-B", builddir, | ||
"-DRDK_BUILD_PGSQL=ON", | ||
"-DPostgreSQL_ROOT=#{postgresql.opt_prefix}", | ||
"-DPostgreSQL_ADDITIONAL_VERSIONS=#{postgresql.version.major}", | ||
*args, *std_cmake_args | ||
system "cmake", "--build", "#{builddir}/Code/PgSQL/rdkit" | ||
system "cmake", "--install", builddir, "--component", "pgsql" | ||
end | ||
end | ||
|
||
def caveats | ||
<<~EOS | ||
You may need to add RDBASE to your environment variables, e.g. | ||
#{Utils::Shell.export_value("RDBASE", "#{opt_share}/RDKit")} | ||
EOS | ||
end | ||
|
||
test do | ||
# Test Python module | ||
ENV["PYTHONPATH"] = prefix/Language::Python.site_packages(python3) | ||
|
||
(testpath/"test.py").write <<~EOS | ||
from rdkit import Chem | ||
print(Chem.MolToSmiles(Chem.MolFromSmiles('C1=CC=CN=C1'))) | ||
EOS | ||
assert_equal "c1ccncc1", shell_output("#{python3} test.py 2>&1").chomp | ||
end | ||
end |