Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rdkit4coot 2024.09.1 (new formula) #1940

Merged
merged 6 commits into from
Oct 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 126 additions & 0 deletions Formula/rdkit4coot.rb
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
Loading