Spaces:
Sleeping
Sleeping
Rocco Meli
commited on
Commit
·
ea2f951
1
Parent(s):
8fee68c
extract markdown from python code
Browse files- app.py +23 -38
- md/acknowledgements.md +4 -0
- md/input.md +4 -0
- md/intro.md +6 -0
- md/scoring.md +7 -0
app.py
CHANGED
@@ -1,24 +1,32 @@
|
|
1 |
import os
|
2 |
|
3 |
|
4 |
-
def
|
5 |
"""
|
6 |
-
Load file
|
7 |
|
8 |
Parameters
|
9 |
----------
|
10 |
-
|
11 |
-
|
12 |
|
13 |
Returns
|
14 |
-------
|
15 |
str
|
16 |
-
|
17 |
"""
|
18 |
-
with open(
|
19 |
return f.read()
|
20 |
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
def load_protein_from_file(protein_file) -> str:
|
23 |
"""
|
24 |
Parameters
|
@@ -199,56 +207,36 @@ if __name__ == "__main__":
|
|
199 |
demo = gr.Blocks()
|
200 |
|
201 |
with demo:
|
202 |
-
gr.Markdown("
|
203 |
-
gr.Markdown(
|
204 |
-
"Score your protein-ligand compex and predict the binding affinity with [Gnina]"
|
205 |
-
+ "(https://github.com/gnina/gnina)'s scoring function. Powered by [gnina-torch]"
|
206 |
-
+ "(https://github.com/RMeli/gnina-torch), a PyTorch implementation of Gnina's"
|
207 |
-
+ " scoring function."
|
208 |
-
)
|
209 |
|
210 |
-
gr.Markdown("
|
211 |
-
gr.Markdown(
|
212 |
-
"Upload your protein and ligand files in PDB and SDF format, respectively."
|
213 |
-
+ " Optionally, you can visualise the protein, the ligand, and the"
|
214 |
-
+ "protein-ligand complex."
|
215 |
-
)
|
216 |
with gr.Row():
|
217 |
with gr.Box():
|
218 |
pfile = gr.File(file_count="single", label="Protein file (PDB)")
|
219 |
gr.Examples(["mols/1cbr_protein.pdb"], inputs=pfile)
|
220 |
-
pbtn = gr.Button("View Protein")
|
221 |
|
222 |
-
|
223 |
-
pbtn.click(fn=protein_html_from_file, inputs=[pfile], outputs=
|
224 |
|
225 |
with gr.Box():
|
226 |
lfile = gr.File(file_count="single", label="Ligand file (SDF)")
|
227 |
gr.Examples(["mols/1cbr_ligand.sdf"], inputs=lfile)
|
228 |
lbtn = gr.Button("View Ligand")
|
229 |
|
230 |
-
|
231 |
-
lbtn.click(fn=ligand_html_from_file, inputs=[lfile], outputs=ligand)
|
232 |
|
233 |
with gr.Box():
|
234 |
with gr.Column():
|
235 |
-
plcomplex = gr.HTML()
|
236 |
-
|
237 |
# TODO: Automatically display complex when both files are uploaded
|
238 |
plbtn = gr.Button("View Protein-Ligand Complex")
|
239 |
plbtn.click(
|
240 |
fn=protein_ligand_html_from_file,
|
241 |
inputs=[pfile, lfile],
|
242 |
-
outputs=
|
243 |
)
|
244 |
|
245 |
-
gr.Markdown("
|
246 |
-
|
247 |
-
"Score your protein-ligand complex with [gnina-torch]"
|
248 |
-
+ "(https://github.com/RMeli/gnina-torch). You can choose between different"
|
249 |
-
+ "pre-trained Gnina models. See [McNutte et al. (2021)]"
|
250 |
-
+ "(https://doi.org/10.1186/s13321-021-00522-2) for more details."
|
251 |
-
)
|
252 |
with gr.Row():
|
253 |
df = gr.Dataframe()
|
254 |
|
@@ -269,10 +257,7 @@ if __name__ == "__main__":
|
|
269 |
btn.click(fn=predict, inputs=[pfile, lfile, dd], outputs=df)
|
270 |
|
271 |
gr.Markdown(
|
272 |
-
"
|
273 |
-
+ "* Simon Dürr, for the blog post [Visualize proteins on Hugging Face Spaces]"
|
274 |
-
+ "(https://huggingface.co/blog/spaces_3dmoljs)\n"
|
275 |
-
+ "* Andrew McNutt, for converting Gnina models' weights to PyTorch"
|
276 |
)
|
277 |
|
278 |
demo.launch()
|
|
|
1 |
import os
|
2 |
|
3 |
|
4 |
+
def load_file(fpath: str) -> str:
|
5 |
"""
|
6 |
+
Load file content.
|
7 |
|
8 |
Parameters
|
9 |
----------
|
10 |
+
fpath: str
|
11 |
+
File path
|
12 |
|
13 |
Returns
|
14 |
-------
|
15 |
str
|
16 |
+
File content
|
17 |
"""
|
18 |
+
with open(fpath, "r") as f:
|
19 |
return f.read()
|
20 |
|
21 |
|
22 |
+
def load_html(html_file: str) -> str:
|
23 |
+
return load_file(os.path.join("html", html_file))
|
24 |
+
|
25 |
+
|
26 |
+
def load_md(md_file: str) -> str:
|
27 |
+
return load_file(os.path.join("md", md_file))
|
28 |
+
|
29 |
+
|
30 |
def load_protein_from_file(protein_file) -> str:
|
31 |
"""
|
32 |
Parameters
|
|
|
207 |
demo = gr.Blocks()
|
208 |
|
209 |
with demo:
|
210 |
+
gr.Markdown(load_md("intro.md"))
|
|
|
|
|
|
|
|
|
|
|
|
|
211 |
|
212 |
+
gr.Markdown(load_md("input.md"))
|
|
|
|
|
|
|
|
|
|
|
213 |
with gr.Row():
|
214 |
with gr.Box():
|
215 |
pfile = gr.File(file_count="single", label="Protein file (PDB)")
|
216 |
gr.Examples(["mols/1cbr_protein.pdb"], inputs=pfile)
|
|
|
217 |
|
218 |
+
pbtn = gr.Button("View Protein")
|
219 |
+
pbtn.click(fn=protein_html_from_file, inputs=[pfile], outputs=gr.HTML())
|
220 |
|
221 |
with gr.Box():
|
222 |
lfile = gr.File(file_count="single", label="Ligand file (SDF)")
|
223 |
gr.Examples(["mols/1cbr_ligand.sdf"], inputs=lfile)
|
224 |
lbtn = gr.Button("View Ligand")
|
225 |
|
226 |
+
lbtn.click(fn=ligand_html_from_file, inputs=[lfile], outputs=gr.HTML())
|
|
|
227 |
|
228 |
with gr.Box():
|
229 |
with gr.Column():
|
|
|
|
|
230 |
# TODO: Automatically display complex when both files are uploaded
|
231 |
plbtn = gr.Button("View Protein-Ligand Complex")
|
232 |
plbtn.click(
|
233 |
fn=protein_ligand_html_from_file,
|
234 |
inputs=[pfile, lfile],
|
235 |
+
outputs=gr.HTML(),
|
236 |
)
|
237 |
|
238 |
+
gr.Markdown(load_md("scoring.md"))
|
239 |
+
|
|
|
|
|
|
|
|
|
|
|
240 |
with gr.Row():
|
241 |
df = gr.Dataframe()
|
242 |
|
|
|
257 |
btn.click(fn=predict, inputs=[pfile, lfile, dd], outputs=df)
|
258 |
|
259 |
gr.Markdown(
|
260 |
+
load_md("acknowledgements.md"),
|
|
|
|
|
|
|
261 |
)
|
262 |
|
263 |
demo.launch()
|
md/acknowledgements.md
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
## Acknowledgements
|
2 |
+
|
3 |
+
* [Simon Dürr](https://simonduerr.eu/), for the blog post [Visualize proteins on Hugging Face Spaces](https://huggingface.co/blog/spaces_3dmoljs)
|
4 |
+
* [Andrew McNutt](https://drewnutt.github.io/), for converting Gnina models' weights to PyTorch
|
md/input.md
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
## Protein and Ligand
|
2 |
+
|
3 |
+
Upload your protein and ligand files in PDB and SDF format, respectively. Optionally,
|
4 |
+
you can visualise the protein, the ligand, and the protein-ligand complex.
|
md/intro.md
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Gnina-Torch
|
2 |
+
|
3 |
+
Score your protein-ligand compex and predict the binding affinity with
|
4 |
+
[Gnina](https://github.com/gnina/gnina)'s scoring function. Powered by
|
5 |
+
[gnina-torch](https://github.com/RMeli/gnina-torch), a PyTorch implementation of Gnina's
|
6 |
+
scoring function.
|
md/scoring.md
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
## Gnina-Torch
|
2 |
+
|
3 |
+
Score you protein-ligand complex with [gnina-torch]().
|
4 |
+
|
5 |
+
You can choose between different pre-trained [Gnina]() models. See
|
6 |
+
[McNutte et al. (2021)](https://doi.org/10.1186/s13321-021-00522-2) for details about
|
7 |
+
the pre-trained models.
|