simonduerr commited on
Commit
47dc822
·
verified ·
1 Parent(s): 0104381

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +21 -0
  2. LICENSE +21 -0
  3. inference_app.py +189 -0
Dockerfile ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM gnina/gnina:v1.1
2
+
3
+ RUN useradd -m -u 1000 user
4
+ WORKDIR /usr/src/app
5
+
6
+ COPY --link --chown=1000 ./ /usr/src/app
7
+ COPY . .
8
+
9
+
10
+ RUN pip3 install rdkit==2023.9.6 pandas==2.1.4 posebusters==0.2.7
11
+ RUN pip3 install gradio gradio_molecule3d
12
+
13
+ RUN git clone https://github.com/rlabduke/reduce.git && cd reduce && make && make install
14
+
15
+ USER user
16
+
17
+ EXPOSE 7860
18
+ ENV GRADIO_SERVER_NAME="0.0.0.0"
19
+
20
+ CMD ["python3", "inference_app.py"]
21
+
LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2024 inductive-bio
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
inference_app.py ADDED
@@ -0,0 +1,189 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Runs the full strong baseline, including smina/vina docking,
2
+ # gnina rescoring, and an input conformational ensemble.
3
+ import argparse
4
+ import os
5
+ import shutil
6
+ import subprocess
7
+
8
+ import pandas as pd
9
+ from rdkit import Chem
10
+ from rdkit.Chem import AllChem, PandasTools, rdMolTransforms
11
+
12
+ import numpy as np
13
+ from moleculekit.molecule import Molecule
14
+
15
+ import time
16
+
17
+ import gradio as gr
18
+
19
+ from gradio_molecule3d import Molecule3D
20
+
21
+ def protonate_receptor_and_ligand(protein,ligand):
22
+ protein_out = protein.replace(".pdb","_H.pdb")
23
+ with open(protein_out, "w") as f:
24
+ subprocess.run(
25
+ ["reduce", "-BUILD", protein],
26
+ stdout=f,
27
+ stderr=subprocess.DEVNULL,
28
+ )
29
+ ligand_out = ligand.replace(".pdb","_H.pdb")
30
+ subprocess.run(["obabel", ligand, "-O", ligand_out, "-p", "7.4"])
31
+
32
+
33
+ def generate_conformers(ligand, num_confs=8):
34
+ mol = Chem.MolFromMolFile(
35
+ ligand.replace(".pdb","_H.pdb")
36
+ )
37
+ mol.RemoveAllConformers()
38
+ mol = Chem.AddHs(mol)
39
+ AllChem.EmbedMultipleConfs(mol, numConfs=num_confs, randomSeed=1)
40
+ AllChem.UFFOptimizeMoleculeConfs(mol)
41
+ with Chem.SDWriter(
42
+ ligand.replace(".pdb","_multiple_confs.pdb")
43
+ ) as writer:
44
+ for cid in range(mol.GetNumConformers()):
45
+ writer.write(mol, confId=cid)
46
+
47
+ def get_bb(points):
48
+ """Return bounding box from a set of points (N,3)
49
+
50
+ Parameters
51
+ ----------
52
+ points : numpy.ndarray
53
+ Set of points (N,3)
54
+
55
+ Returns
56
+ -------
57
+ boundingBox : list
58
+ List of the form [xmin, xmax, ymin, ymax, zmin, zmax]
59
+
60
+ """
61
+ minx = np.min(points[:, 0])
62
+ maxx = np.max(points[:, 0])
63
+
64
+ miny = np.min(points[:, 1])
65
+ maxy = np.max(points[:, 1])
66
+
67
+ minz = np.min(points[:, 2])
68
+ maxz = np.max(points[:, 2])
69
+ bb = [[minx, miny, minz], [maxx, maxy, maxz]]
70
+ return bb
71
+
72
+ def run_docking(protein, ligand):
73
+
74
+ mol = Molecule(protein)
75
+ mol.center()
76
+ bb = get_bb(mol.coords)
77
+ size_x = bb[1][0] - bb[0][0]
78
+ size_y = bb[1][1] - bb[0][1]
79
+ size_z = bb[1][2] - bb[0][2]
80
+
81
+ subprocess.run(
82
+ [
83
+ "gnina",
84
+ "-r",
85
+ protein.replace(".pdb","_H.pdb"),
86
+ "-l",
87
+ ligand.replace(".sdf","_ligand_multiple_confs.sdf"),
88
+ "-o",
89
+ ligand.replace(".sdf","_multiple_confs_poses.sdf"),
90
+ "--center_x", # bounding box matching PoseBusters methodology
91
+ str(0),
92
+ "--center_y",
93
+ str(0),
94
+ "--center_z",
95
+ str(0),
96
+ "--size_x",
97
+ str(size_x),
98
+ "--size_y",
99
+ str(size_y),
100
+ "--size_z",
101
+ str(size_z),
102
+ "--scoring",
103
+ "vina",
104
+ "--exhaustiveness",
105
+ "4",
106
+ "--num_modes",
107
+ "1",
108
+ "--seed",
109
+ "1",
110
+ ]
111
+ )
112
+ # sort the poses from the multiple conformation runs, so overall best is first
113
+ poses = PandasTools.LoadSDF(
114
+ ligand.replace(".sdf","_multiple_confs_poses.sdf")
115
+ )
116
+ poses["CNNscore"] = poses["CNNscore"].astype(float)
117
+ gnina_order = poses.sort_values("CNNscore", ascending=False).reset_index(drop=True)
118
+ PandasTools.WriteSDF(
119
+ gnina_order,
120
+ ligand.replace(".sdf","_multiple_confs_poses.sdf")
121
+ properties=list(poses.columns),
122
+ )
123
+ return poses["CNNscore"]
124
+
125
+
126
+ def predict (input_sequence, input_ligand,input_msa, input_protein):
127
+ start_time = time.time()
128
+
129
+ protonate_receptor_and_ligand(input_protein, input_ligand)
130
+ generate_conformers(input_protein, input_ligand)
131
+ cnn_score = run_docking(input_protein, input_ligand)
132
+ metrics = {"cnn_score": cnn_score}
133
+ end_time = time.time()
134
+ run_time = end_time - start_time
135
+ return ["test_out.pdb", "test_docking_pose.sdf"], metrics, run_time
136
+
137
+ with gr.Blocks() as app:
138
+
139
+ gr.Markdown("# Template for inference")
140
+
141
+ gr.Markdown("Title, description, and other information about the model")
142
+ with gr.Row():
143
+ input_sequence = gr.Textbox(lines=3, label="Input Protein sequence (FASTA)")
144
+ input_ligand = gr.Textbox(lines=3, label="Input ligand SMILES")
145
+ with gr.Row():
146
+ input_msa = gr.File(label="Input Protein MSA (A3M)")
147
+ input_protein = gr.File(label="Input protein monomer")
148
+
149
+
150
+ # define any options here
151
+
152
+ # for automated inference the default options are used
153
+ # slider_option = gr.Slider(0,10, label="Slider Option")
154
+ # checkbox_option = gr.Checkbox(label="Checkbox Option")
155
+ # dropdown_option = gr.Dropdown(["Option 1", "Option 2", "Option 3"], label="Radio Option")
156
+
157
+ btn = gr.Button("Run Inference")
158
+
159
+ gr.Examples(
160
+ [
161
+ [
162
+ "SVKSEYAEAAAVGQEAVAVFNTMKAAFQNGDKEAVAQYLARLASLYTRHEELLNRILEKARREGNKEAVTLMNEFTATFQTGKSIFNAMVAAFKNGDDDSFESYLQALEKVTAKGETLADQIAKAL:SVKSEYAEAAAVGQEAVAVFNTMKAAFQNGDKEAVAQYLARLASLYTRHEELLNRILEKARREGNKEAVTLMNEFTATFQTGKSIFNAMVAAFKNGDDDSFESYLQALEKVTAKGETLADQIAKAL",
163
+ "COc1ccc(cc1)n2c3c(c(n2)C(=O)N)CCN(C3=O)c4ccc(cc4)N5CCCCC5=O",
164
+ "test_out.pdb"
165
+ ],
166
+ ],
167
+ [input_sequence, input_ligand, input_protein],
168
+ )
169
+ reps = [
170
+ {
171
+ "model": 0,
172
+ "style": "cartoon",
173
+ "color": "whiteCarbon",
174
+ },
175
+ {
176
+ "model": 1,
177
+ "style": "stick",
178
+ "color": "greenCarbon",
179
+ }
180
+
181
+ ]
182
+
183
+ out = Molecule3D(reps=reps)
184
+ metrics = gr.JSON(label="Metrics")
185
+ run_time = gr.Textbox(label="Runtime")
186
+
187
+ btn.click(predict, inputs=[input_sequence, input_ligand, input_msa, input_protein], outputs=[out,metrics, run_time])
188
+
189
+ app.launch()