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

feat: Rdkit cart substructure search #2055

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
101 changes: 101 additions & 0 deletions Dockerfile.RDKit
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# https://github.com/rvianello/docker-postgres-rdkit/blob/master/Dockerfile
ARG postgres_image_version=16 # changed from 16.2
FROM docker.io/postgres:${postgres_image_version} AS builder
ARG postgres_version=16
ARG boost_dev_version=1.74
ARG rdkit_git_url=https://github.com/rdkit/rdkit.git
ARG rdkit_git_ref=Release_2024_03_1

RUN apt-get update \
&& apt-get install -yq --no-install-recommends \
ca-certificates \
curl \
gnupg \
lsb-release \
&& curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
&& echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list

RUN apt-get update \
&& apt-get install -yq --no-install-recommends \
build-essential \
cmake \
git \
coreutils \
libboost-iostreams${boost_dev_version}-dev \
libboost-regex${boost_dev_version}-dev \
libboost-serialization${boost_dev_version}-dev \
libboost-system${boost_dev_version}-dev \
libeigen3-dev \
libfreetype6-dev \
postgresql-server-dev-${postgres_version} \
zlib1g-dev \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

RUN mkdir -p /opt/RDKit-build \
&& chown postgres:postgres /opt/RDKit-build

USER postgres
WORKDIR /opt/RDKit-build

RUN git clone ${rdkit_git_url}
WORKDIR /opt/RDKit-build/rdkit
RUN git checkout ${rdkit_git_ref}

RUN cmake \
-D RDK_BUILD_CAIRO_SUPPORT=OFF \
-D RDK_BUILD_INCHI_SUPPORT=ON \
-D RDK_BUILD_AVALON_SUPPORT=ON \
-D RDK_BUILD_PYTHON_WRAPPERS=OFF \
-D RDK_BUILD_DESCRIPTORS3D=OFF \
-D RDK_BUILD_FREESASA_SUPPORT=OFF \
-D RDK_BUILD_COORDGEN_SUPPORT=ON \
-D RDK_BUILD_MOLINTERCHANGE_SUPPORT=OFF \
-D RDK_BUILD_YAEHMOP_SUPPORT=OFF \
-D RDK_BUILD_STRUCTCHECKER_SUPPORT=OFF \
-D RDK_USE_URF=OFF \
-D RDK_BUILD_PGSQL=ON \
-D RDK_PGSQL_STATIC=ON \
-D PostgreSQL_CONFIG=pg_config \
-D PostgreSQL_INCLUDE_DIR=`pg_config --includedir` \
-D PostgreSQL_TYPE_INCLUDE_DIR=`pg_config --includedir-server` \
-D PostgreSQL_LIBRARY_DIR=`pg_config --libdir` \
-D RDK_INSTALL_INTREE=OFF \
-D CMAKE_INSTALL_PREFIX=/opt/RDKit \
-D CMAKE_BUILD_TYPE=Release \
.
RUN make -j$(nproc)

USER root
WORKDIR /opt/RDKit-build/rdkit

RUN make install
RUN /bin/bash /opt/RDKit-build/rdkit/Code/PgSQL/rdkit/pgsql_install.sh

USER postgres
WORKDIR /opt/RDKit-build/rdkit

RUN initdb -D /opt/RDKit-build/pgdata \
&& pg_ctl -D /opt/RDKit-build/pgdata -l /opt/RDKit-build/pgdata/log.txt start \
&& RDBASE="$PWD" LD_LIBRARY_PATH="$PWD/lib" ctest -j4 --output-on-failure \
&& pg_ctl -D /opt/RDKit-build/pgdata stop


FROM docker.io/postgres:${postgres_image_version}
ARG postgres_version=16
ARG boost_version=1.74.0

RUN apt-get update \
&& apt-get install -yq --no-install-recommends \
libboost-iostreams${boost_version} \
libboost-regex${boost_version} \
libboost-serialization${boost_version} \
libboost-system${boost_version} \
libfreetype6 \
zlib1g \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

COPY --from=builder /usr/share/postgresql/${postgres_version}/extension/*rdkit* /usr/share/postgresql/${postgres_version}/extension/
COPY --from=builder /usr/lib/postgresql/${postgres_version}/lib/rdkit.so /usr/lib/postgresql/${postgres_version}/lib/rdkit.so

5 changes: 2 additions & 3 deletions Dockerfile.chemotion-dev
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ ARG DEBIAN_FRONTEND=noninteractive
RUN set -xe && apt-get update -yqqq --fix-missing && apt-get upgrade -y
RUN apt update && apt-get install -yqq --fix-missing bash ca-certificates wget apt-transport-https git gpg\
imagemagick libmagic-dev libmagickcore-dev libmagickwand-dev curl gnupg2 \
build-essential sudo postgresql-client libappindicator1 swig \
gconf-service libasound2 libgconf-2-4 cmake \
libnspr4 libnss3 libpango1.0-0 libxss1 xdg-utils tzdata libpq-dev \
build-essential sudo postgresql-client swig cmake \
libnspr4 libnss3 libxss1 xdg-utils tzdata libpq-dev \
gtk2-engines-pixbuf \
libssl-dev libreadline-dev\
unzip openssh-client \
Expand Down
20 changes: 11 additions & 9 deletions app/api/chemotion/search_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class SearchAPI < Grape::API
All Samples Reactions Wellplates Screens all samples reactions wellplates screens elements cell_lines by_ids advanced structure
]
optional :molfile, type: String
optional :search_type, type: String, values: %w[similar sub]
optional :search_type, type: String, values: %w[similar sub subRDKit]
optional :tanimoto_threshold, type: Float
optional :page_size, type: Integer
optional :structure_search, type: Boolean
Expand Down Expand Up @@ -97,10 +97,13 @@ def sample_structure_search(c_id = @c_id, not_permitted = @dl_s && @dl_s < 1)

# TODO: implement this: http://pubs.acs.org/doi/abs/10.1021/ci600358f
scope =
if params[:selection][:search_type] == 'similar'
case params[:selection][:search_type]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This switch case seems to be replicating the switch case under usecases/search/structure_search.rb. Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

usecases/search/structure_search.rb removed

when 'similar'
Sample.by_collection_id(c_id).search_by_fingerprint_sim(molfile, threshold)
else
when 'sub'
Sample.by_collection_id(c_id).search_by_fingerprint_sub(molfile)
when 'subRDKit'
Sample.by_collection_id(c_id).search_by_rdkit_sub(molfile)
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed adding a fallback / default case for invalid search_type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The search type has a whitelist: "optional :search_type, type: String, values: %w[similar sub subRDKit]"
Do we still need a fallback / default case?

order_by_molecule(scope)
end
Expand Down Expand Up @@ -519,12 +522,11 @@ def elements_by_scope(scope, collection_id = @c_id)
end

post do
Usecases::Search::StructureSearch.new(
collection_id: @c_id,
params: params,
user: current_user,
detail_levels: @dl,
).perform!
samples = sample_structure_search
JanCBrammer marked this conversation as resolved.
Show resolved Hide resolved
serialization_by_elements_and_page(
elements_by_scope(samples),
params[:page],
)
end
end

Expand Down
1 change: 1 addition & 0 deletions app/api/chemotion/ui_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class UiAPI < Grape::API
has_radar: radar_config.present?,
molecule_viewer: Matrice.molecule_viewer,
collector_address: collector_address.presence,
pg_cartridge: Chemotion::Application.config.pg_cartridge,
third_party_apps: Entities::ThirdPartyAppEntity.represent(ThirdPartyApp.all),
}
end
Expand Down
1 change: 1 addition & 0 deletions app/models/fingerprint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class Fingerprint < ApplicationRecord
fp_vector = Chemotion::OpenBabelService.bin_fingerprint_from_molfile(molfile) if molfile
threshold = threshold.to_f
query_num_set_bits = count_bits_set(fp_vector)
return none unless query_num_set_bits.positive?

sim_query = sanitize_sql_for_conditions(
[sql_query_similar, query_num_set_bits] + fp_vector + [
Expand Down
Loading
Loading