Spaces:
Sleeping
Sleeping
Display ligand (SDF) file as well as protein.
Browse files- main.py +3 -3
- mol_viewer.py +18 -11
- run_utils.py +15 -7
main.py
CHANGED
@@ -16,13 +16,13 @@ def run_wrapper(protein_file, ligand_file, other_args_file, *args, **kwargs) ->
|
|
16 |
if other_args_file is not None:
|
17 |
kwargs["other_arg_file"] = other_args_file.name
|
18 |
|
19 |
-
output_file,
|
20 |
protein_file.name, ligand_file.name, *args, **kwargs
|
21 |
)
|
22 |
|
23 |
output_viz = "No visualisation created"
|
24 |
-
if
|
25 |
-
output_viz = mol_viewer.gen_3dmol_vis(
|
26 |
|
27 |
message = f"Calculation completed at {datetime.datetime.now()}"
|
28 |
return message, output_file, output_viz
|
|
|
16 |
if other_args_file is not None:
|
17 |
kwargs["other_arg_file"] = other_args_file.name
|
18 |
|
19 |
+
output_file, pdb_text, sdf_text = run_utils.run_cli_command(
|
20 |
protein_file.name, ligand_file.name, *args, **kwargs
|
21 |
)
|
22 |
|
23 |
output_viz = "No visualisation created"
|
24 |
+
if pdb_text:
|
25 |
+
output_viz = mol_viewer.gen_3dmol_vis(pdb_text, sdf_text)
|
26 |
|
27 |
message = f"Calculation completed at {datetime.datetime.now()}"
|
28 |
return message, output_file, output_viz
|
mol_viewer.py
CHANGED
@@ -9,9 +9,7 @@ https://huggingface.co/spaces/simonduerr/3dmol.js/blob/main/app.py
|
|
9 |
"""
|
10 |
|
11 |
|
12 |
-
def gen_3dmol_vis(pdb_text: str):
|
13 |
-
mol = pdb_text
|
14 |
-
|
15 |
x = (
|
16 |
"""<!DOCTYPE html>
|
17 |
<html>
|
@@ -38,26 +36,35 @@ def gen_3dmol_vis(pdb_text: str):
|
|
38 |
<div id="container" class="mol-container"></div>
|
39 |
|
40 |
<script>
|
41 |
-
let pdb = `"""
|
42 |
-
|
43 |
-
|
44 |
|
45 |
$(document).ready(function () {
|
46 |
let element = $("#container");
|
47 |
let config = { backgroundColor: "white" };
|
48 |
let viewer = $3Dmol.createViewer(element, config);
|
49 |
-
|
50 |
-
viewer.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
viewer.zoomTo();
|
52 |
viewer.render();
|
53 |
-
viewer.zoom(0.8, 2000);
|
54 |
})
|
55 |
</script>
|
56 |
</body></html>"""
|
57 |
)
|
58 |
|
59 |
-
return f"""<iframe style="width: 100%; height: 600px" name="result"
|
60 |
-
display-capture; encrypted-media;" sandbox="allow-modals allow-forms
|
61 |
allow-scripts allow-same-origin allow-popups
|
62 |
allow-top-navigation-by-user-activation allow-downloads" allowfullscreen=""
|
63 |
allowpaymentrequest="" frameborder="0" srcdoc='{x}'></iframe>"""
|
|
|
9 |
"""
|
10 |
|
11 |
|
12 |
+
def gen_3dmol_vis(pdb_text: str, sdf_text: str):
|
|
|
|
|
13 |
x = (
|
14 |
"""<!DOCTYPE html>
|
15 |
<html>
|
|
|
36 |
<div id="container" class="mol-container"></div>
|
37 |
|
38 |
<script>
|
39 |
+
let pdb = `""" + pdb_text + """`
|
40 |
+
|
41 |
+
let sdf = `""" + sdf_text + """`
|
42 |
|
43 |
$(document).ready(function () {
|
44 |
let element = $("#container");
|
45 |
let config = { backgroundColor: "white" };
|
46 |
let viewer = $3Dmol.createViewer(element, config);
|
47 |
+
|
48 |
+
viewer.addModel(pdb, "pdb", { format: "pdb" });
|
49 |
+
pdb_model = viewer.getModel(0);
|
50 |
+
// Cartoon view for protein
|
51 |
+
// First argument is a selector
|
52 |
+
pdb_model.setStyle({}, {cartoon: {color: "spectrum", opacity: 0.8}});
|
53 |
+
|
54 |
+
viewer.addModel(sdf, "sdf", {format: "sdf"});
|
55 |
+
sdf_model = viewer.getModel(1);
|
56 |
+
// Stick view for SDF
|
57 |
+
sdf_model.setStyle({}, {stick: {color: "red", radius: 0.2, opacity: 0.8}});
|
58 |
+
|
59 |
viewer.zoomTo();
|
60 |
viewer.render();
|
61 |
+
// viewer.zoom(0.8, 2000);
|
62 |
})
|
63 |
</script>
|
64 |
</body></html>"""
|
65 |
)
|
66 |
|
67 |
+
return f"""<iframe style="width: 100%; height: 600px" name="result" sandbox="allow-modals allow-forms
|
|
|
68 |
allow-scripts allow-same-origin allow-popups
|
69 |
allow-top-navigation-by-user-activation allow-downloads" allowfullscreen=""
|
70 |
allowpaymentrequest="" frameborder="0" srcdoc='{x}'></iframe>"""
|
run_utils.py
CHANGED
@@ -124,15 +124,23 @@ def run_cli_command(
|
|
124 |
# If there's a file for viewing, load it and view it.
|
125 |
sub_dirs = [os.path.join(temp_dir_path, x) for x in os.listdir(temp_dir_path)]
|
126 |
sub_dirs = list(filter(lambda x: os.path.isdir(x), sub_dirs))
|
127 |
-
|
128 |
if len(sub_dirs) == 1:
|
129 |
-
|
|
|
|
|
130 |
|
131 |
-
if
|
132 |
-
|
|
|
|
|
|
|
133 |
|
134 |
-
|
135 |
-
|
|
|
|
|
|
|
136 |
|
137 |
# Zip the output directory
|
138 |
# Generate a unique filename using a timestamp and a UUID
|
@@ -144,7 +152,7 @@ def run_cli_command(
|
|
144 |
|
145 |
logging.debug(f"Directory '{temp_dir}' zipped to '{full_zip_path}'")
|
146 |
|
147 |
-
return full_zip_path,
|
148 |
|
149 |
|
150 |
if __name__ == "__main__":
|
|
|
124 |
# If there's a file for viewing, load it and view it.
|
125 |
sub_dirs = [os.path.join(temp_dir_path, x) for x in os.listdir(temp_dir_path)]
|
126 |
sub_dirs = list(filter(lambda x: os.path.isdir(x), sub_dirs))
|
127 |
+
pdb_path = pdb_text = sdf_path = sdf_text = None
|
128 |
if len(sub_dirs) == 1:
|
129 |
+
sub_dir = sub_dirs[0]
|
130 |
+
pdb_path = os.path.join(sub_dir, "rank1_reverseprocess_protein.pdb")
|
131 |
+
sdf_path = os.path.join(sub_dir, "rank1.sdf")
|
132 |
|
133 |
+
if skip_running:
|
134 |
+
# Test/debugging only
|
135 |
+
example_dir = os.path.join(os.environ["HOME"], "Projects", "DiffDock-Pocket", "example_data", "example_outputs")
|
136 |
+
pdb_path = os.path.join(example_dir, "rank1_reverseprocess_protein.pdb")
|
137 |
+
sdf_path = os.path.join(example_dir, "rank1.sdf")
|
138 |
|
139 |
+
if pdb_path and os.path.exists(pdb_path):
|
140 |
+
pdb_text = read_file_lines(pdb_path)
|
141 |
+
sdf_text = read_file_lines(sdf_path)
|
142 |
+
|
143 |
+
logging.debug(f"Display path: {pdb_path}")
|
144 |
|
145 |
# Zip the output directory
|
146 |
# Generate a unique filename using a timestamp and a UUID
|
|
|
152 |
|
153 |
logging.debug(f"Directory '{temp_dir}' zipped to '{full_zip_path}'")
|
154 |
|
155 |
+
return full_zip_path, pdb_text, sdf_text
|
156 |
|
157 |
|
158 |
if __name__ == "__main__":
|