DiffLinker / app.py
igashov's picture
Update app.py
4cfe680
raw
history blame
1.66 kB
import gradio as gr
import os
import sys
HTML_TEMPLATE = '''<!DOCTYPE html>
<html>
<head>
<script src="https://3Dmol.csb.pitt.edu/build/3Dmol-min.js"></script>
</head>
<body>
<h1>Result:</h1>
{content}
</body>
</html>
'''
VIS_TEMPLATE = '''
<div id="container" class="mol-container"></div>
<script>
let ligand = `{path}`
let viewer = null;
$(document).ready(function () {
let element = $("#container");
let config = { backgroundColor: "white" };
viewer = $3Dmol.createViewer(element, config);
viewer.addModel( ligand, "Molecule" )
viewer.getModel(1).setStyle({stick:{colorscheme:"magentaCarbon"}});
viewer.render();
})
</script>
'''
def generate(input_file):
try:
path = input_file.name
except:
return HTML_TEMPLATE.format(content='Error: could not open the provided file')
content = VIS_TEMPLATE.format(path=path)
return HTML_TEMPLATE.format(content=content)
demo = gr.Blocks()
with demo:
gr.Markdown('# DiffLinker: Equivariant 3D-Conditional Diffusion Model for Molecular Linker Design')
with gr.Box():
with gr.Row():
with gr.Column():
gr.Markdown('## Input Fragments')
gr.Markdown('Upload the file with 3D-coordinates of the input fragments in .pdb, .mol or .sdf format')
input_file = gr.File(file_count='single', label='Input fragments in .pdb, .mol2 or .sdf format')
button = gr.Button('Generate Linker!')
gr.Markdown('')
visualization = gr.HTML()
button.click(
fn=generate,
inputs=[input_file],
outputs=[visualization],
)
demo.launch()