File size: 2,562 Bytes
7782ac2
 
 
 
 
4470746
711f689
200cdf1
 
 
0673854
200cdf1
 
 
0673854
 
dd9ffc6
0673854
200cdf1
4470746
200cdf1
 
 
 
 
0673854
4470746
9f1ea4e
4470746
0673854
9f1ea4e
4470746
 
0673854
200cdf1
 
711f689
4470746
711f689
81748f8
 
 
 
 
0673854
 
 
 
 
 
7782ac2
 
 
0673854
 
7782ac2
200cdf1
7782ac2
0673854
81748f8
7782ac2
 
 
 
 
 
 
711f689
 
f8e8929
ebb60a3
7782ac2
 
 
711f689
7782ac2
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import gradio as gr
import os
import sys


HTML_TEMPLATE = """<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
        <style>
            .mol-container {{
                width: 600px;
                height: 600px;
                position: relative;
            }}
            .mol-container select{{
                background-image:None;
            }}
        </style>
        <script src="https://3Dmol.csb.pitt.edu/build/3Dmol-min.js"></script>
    </head>
    
    <body>
    <div id="container" class="mol-container"></div>
    <script>
        $(document).ready(function() {{
            let element = $("#container");
            let config = {{ backgroundColor: "white" }};
            let viewer = $3Dmol.createViewer( element, config );
            viewer.addModel(`{molecule}`, "{fmt}")
            viewer.getModel().setStyle({{ stick: {{ colorscheme:"greenCarbon" }} }})
            viewer.zoomTo();
            viewer.render();
        }});
    </script>
    </body>
</html>
"""

IFRAME_TEMPLATE = """<iframe style="width: 100%; height: 700px" name="result" allow="midi; geolocation; microphone; camera; 
display-capture; encrypted-media;" sandbox="allow-modals allow-forms allow-scripts allow-same-origin allow-popups 
allow-top-navigation-by-user-activation allow-downloads" allowfullscreen="" 
allowpaymentrequest="" frameborder="0" srcdoc='{html}'></iframe>"""


def read_molecule(path):
    with open(path, "r") as f:
        return "".join(f.readlines())


def generate(input_file):
    try:
        path = input_file.name
        molecule = read_molecule(path)
        fmt = path.split('.')[-1]
    except:
        return 'Error: could not open the provided file'
    
    html = HTML_TEMPLATE.format(molecule=molecule, fmt=fmt)
    return IFRAME_TEMPLATE.format(html=html)


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, .mol2 or .sdf format')
                input_file = gr.File(file_count='single', label='Input fragments')
            
    button = gr.Button('Generate Linker!')
    
    gr.Markdown('')
    visualization = gr.HTML()
    
    button.click(
        fn=generate,
        inputs=[input_file],
        outputs=[visualization],
    )

demo.launch()