File size: 4,645 Bytes
5c0a4b6
 
7fc9185
6daa4cc
275b482
7fc9185
5c0a4b6
6daa4cc
7fc9185
 
275b482
 
5c0a4b6
 
 
 
 
40e4bad
 
 
 
 
 
 
 
 
 
 
 
 
 
275b482
0303515
275b482
5c0a4b6
b1dc6ad
275b482
28fb149
e533974
5c0a4b6
b1dc6ad
 
5c0a4b6
 
 
 
e533974
7fc9185
5c0a4b6
 
 
 
 
 
 
 
 
275b482
 
5c0a4b6
275b482
 
 
 
 
40e4bad
 
 
 
 
275b482
5c0a4b6
 
0303515
5c0a4b6
275b482
5c0a4b6
 
 
 
 
 
 
 
 
 
 
 
275b482
 
 
5c0a4b6
275b482
7fc9185
5c0a4b6
6daa4cc
 
7fc9185
28fb149
6daa4cc
 
e533974
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import datetime
from typing import Tuple, Optional

import gradio as gr
import yaml

import mol_viewer
import run_utils


def run_wrapper(protein_file, ligand_file, other_args_file, *args) -> Tuple[str, Optional[str], str]:

    if protein_file is None:
        return "Protein file is missing! Must provide a protein file in PDB format", None, ""
    if ligand_file is None:
        return "Ligand file is missing! Must provide a ligand file in SDF format", None, ""

    float_locs = [-4, -3, -2]
    num_centers = 0
    for ii in float_locs:
        av = args[ii]
        if av is not None and av != "":
            num_centers += 1
            try:
                tmp = float(args[ii])
            except ValueError:
                return f"Pocket Center value {args[ii]} is not a valid number", None, ""

    if num_centers not in {0, 3}:
        return "Either none or all three pocket center values must be provided", None, ""

    other_args_dict = {}
    if other_args_file is not None:
        other_args_dict = yaml.safe_load(open(other_args_file['name'], "r"))

    output_file, pdb_text, sdf_text = run_utils.run_cli_command(
        protein_file['name'], ligand_file['name'], other_args_dict, *args,
    )

    output_viz = "No visualisation created"
    if pdb_text:
        output_viz = mol_viewer.gen_3dmol_vis(pdb_text, sdf_text)

    message = f"Calculation completed at {datetime.datetime.now()}"
    return message, output_file, output_viz


def run():

    with gr.Blocks(title="DiffDock-Pocket Web") as demo:
        gr.Markdown("# DiffDock-Pocket")
        gr.Markdown("""Run [DiffDock-Pocket](https://github.com/plainerman/DiffDock-Pocket) for a single protein and ligand.
        We have provided the most important inputs as UI elements.  """)
        with gr.Row():
            protein_pdb = gr.File(label="Protein PDB (required)", file_types=[".pdb"])
            ligand_sdf = gr.File(label="Ligand SDF (required)", file_types=[".sdf"])
        with gr.Row():
            samples_per_complex = gr.Number(label="Samples Per Complex", value=1, minimum=1, maximum=100, precision=0,
                                            interactive=True)
            with gr.Column():
                keep_local_structures = gr.Checkbox(label="Keep Local Structures", value=True, interactive=True)
                save_vis = gr.Checkbox(label="Save Visualisation", value=True, interactive=True,
                                       elem_id="save_visualisation")
        with gr.Row():
            # Add fields for pocket_center_x, pocket_center_y, pocket_center_z
            pcx = gr.Text(label="Pocket Center X", placeholder="1.23", value=None, interactive=True)
            pcy = gr.Text(label="Pocket Center Y", placeholder="4.56", value=None, interactive=True)
            pcz = gr.Text(label="Pocket Center Z", placeholder="7.89", value=None, interactive=True)
            flex_sidechains = gr.Textbox(label="Flexible Sidechains", placeholder="A:130-B:140", value=None,
                                         interactive=True,
                                         info="Specify which amino acids will be flexible. E.g., A:130-B:140 will make amino acid with id 130 in chain A, and id 140 in chain B flexible.")
        with gr.Row():
            gr.Markdown("""Additional values can be included in "Other arguments", and will be passed 
        to [inference.py](https://github.com/plainerman/DiffDock-Pocket/blob/main/inference.py). 
        Must be a YAML file without any nesting.  """)
            other_args_file = gr.File(label="Other arguments (Optional, YML)", file_types=[".yml", ".yaml"], value=None)

        with gr.Row():
            run_btn = gr.Button("Run DiffDock-Pocket")

        with gr.Row():
            message = gr.Text(label="Run message", interactive=False)
        with gr.Row():
            output_file = gr.File(label="Output Files")
        with gr.Row():
            init_value = "Rank1 Reverse Processed Protein will be visualised here"
            viewer = gr.HTML(value=init_value, label="Protein Viewer", show_label=True)

        _inputs = [protein_pdb, ligand_sdf, other_args_file]
        # See run_utils.py:ARG_ORDER for the order of these arguments
        _inputs += [samples_per_complex, keep_local_structures, save_vis, pcx, pcy, pcz, flex_sidechains]
        _outputs = [message, output_file, viewer]
        run_btn.click(fn=run_wrapper, inputs=_inputs, outputs=_outputs, preprocess=False)

    demo.launch(server_name="0.0.0.0", server_port=7860, share=False)


if __name__ == "__main__":
    run_utils.set_env_variables()
    run_utils.configure_logging()

    run()