silterra commited on
Commit
28fb149
·
1 Parent(s): 6daa4cc

Some reformatting and refactoring. Upgrade gradio to 3.50.

Browse files
Files changed (3) hide show
  1. basic_environment.yml +1 -1
  2. main.py +4 -15
  3. run_utils.py +52 -17
basic_environment.yml CHANGED
@@ -9,4 +9,4 @@ dependencies:
9
  - pip=23.3.1
10
  - pytorch=1.13.1
11
  - pip:
12
- - streamlit==1.28
 
9
  - pip=23.3.1
10
  - pytorch=1.13.1
11
  - pip:
12
+ - gradio==3.50
main.py CHANGED
@@ -7,8 +7,9 @@ import run_utils
7
 
8
 
9
  def run_wrapper(protein_file, ligand_file, *args, **kwargs) -> str:
10
- return run_utils.run_cli_command(protein_file.name, ligand_file.name,
11
- *args, **kwargs)
 
12
 
13
 
14
  def run():
@@ -33,20 +34,8 @@ def run():
33
  iface.launch(server_name="0.0.0.0", server_port=7860, share=False)
34
 
35
 
36
- def set_env_variables():
37
- if "DiffDock-Pocket-Dir" not in os.environ:
38
- work_dir = os.path.abspath(os.path.join("../DiffDock-Pocket"))
39
- if os.path.exists(work_dir):
40
- os.environ["DiffDock-Pocket-Dir"] = work_dir
41
- else:
42
- raise ValueError(f"DiffDock-Pocket-Dir {work_dir} not found")
43
-
44
- if "LOG_LEVEL" not in os.environ:
45
- os.environ["LOG_LEVEL"] = "INFO"
46
-
47
-
48
  if __name__ == "__main__":
49
- set_env_variables()
50
  run_utils.configure_logging()
51
 
52
  run()
 
7
 
8
 
9
  def run_wrapper(protein_file, ligand_file, *args, **kwargs) -> str:
10
+ return run_utils.run_cli_command(
11
+ protein_file.name, ligand_file.name, *args, **kwargs
12
+ )
13
 
14
 
15
  def run():
 
34
  iface.launch(server_name="0.0.0.0", server_port=7860, share=False)
35
 
36
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  if __name__ == "__main__":
38
+ run_utils.set_env_variables()
39
  run_utils.configure_logging()
40
 
41
  run()
run_utils.py CHANGED
@@ -8,6 +8,18 @@ import uuid
8
  import logging
9
 
10
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  def configure_logging(level=None):
12
  if level is None:
13
  level = getattr(logging, os.environ.get("LOG_LEVEL", "INFO"))
@@ -16,24 +28,35 @@ def configure_logging(level=None):
16
  # which includes other libraries.
17
  logging.basicConfig(
18
  level=level,
19
- format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
20
  handlers=[
21
  logging.StreamHandler(), # Outputs logs to stderr by default
22
  # If you also want to log to a file, uncomment the following line:
23
  # logging.FileHandler('my_app.log', mode='a', encoding='utf-8')
24
- ]
25
  )
26
 
27
 
28
- def run_cli_command(protein_path: str, ligand: str, samples_per_complex: int,
29
- keep_local_structures: bool, save_visualisation: bool, work_dir=None):
30
-
 
 
 
 
 
31
  if work_dir is None:
32
- work_dir = os.environ.get("DiffDock-Pocket-Dir",
33
- os.path.join(os.environ["HOME"], "DiffDock-Pocket"))
34
-
35
- command = ["python3", "inference.py", f"--protein_path={protein_path}", f"--ligand={ligand}",
36
- f"--samples_per_complex={samples_per_complex}"]
 
 
 
 
 
 
37
 
38
  # Adding boolean arguments only if they are True
39
  if keep_local_structures:
@@ -43,7 +66,6 @@ def run_cli_command(protein_path: str, ligand: str, samples_per_complex: int,
43
 
44
  with tempfile.TemporaryDirectory() as temp_dir:
45
  temp_dir_path = temp_dir
46
- logging.debug(f"temp dir: {temp_dir}")
47
  command.append(f"--out_dir={temp_dir_path}")
48
 
49
  # Convert command list to string for printing
@@ -53,7 +75,12 @@ def run_cli_command(protein_path: str, ligand: str, samples_per_complex: int,
53
  # Running the command
54
  try:
55
  result = subprocess.run(
56
- command, cwd=work_dir, check=False, text=True, capture_output=True, env=os.environ
 
 
 
 
 
57
  )
58
  logging.debug(f"Command output:\n{result.stdout}")
59
  if result.stderr:
@@ -67,19 +94,27 @@ def run_cli_command(protein_path: str, ligand: str, samples_per_complex: int,
67
  uuid_tag = str(uuid.uuid4())[0:8]
68
  unique_filename = f"output_{timestamp}_{uuid_tag}"
69
  zip_base_name = os.path.join("tmp", unique_filename)
70
- full_zip_path = shutil.make_archive(zip_base_name, 'zip', temp_dir)
71
 
72
  logging.debug(f"Directory '{temp_dir}' zipped to '{full_zip_path}'")
73
 
74
  return full_zip_path
75
 
76
 
77
- if False and __name__ == "__main__":
78
  # Testing code
79
- work_dir = os.path.expanduser("~/Projects/DiffDock-Pocket")
 
 
 
80
  os.environ["DiffDock-Pocket-Dir"] = work_dir
81
  protein_path = os.path.join(work_dir, "example_data", "3dpf_protein.pdb")
82
  ligand = os.path.join(work_dir, "example_data", "3dpf_ligand.sdf")
83
 
84
- run_cli_command(protein_path, ligand, samples_per_complex=1,
85
- keep_local_structures=True, save_visualisation=True)
 
 
 
 
 
 
8
  import logging
9
 
10
 
11
+ def set_env_variables():
12
+ if "DiffDock-Pocket-Dir" not in os.environ:
13
+ work_dir = os.path.abspath(os.path.join("../DiffDock-Pocket"))
14
+ if os.path.exists(work_dir):
15
+ os.environ["DiffDock-Pocket-Dir"] = work_dir
16
+ else:
17
+ raise ValueError(f"DiffDock-Pocket-Dir {work_dir} not found")
18
+
19
+ if "LOG_LEVEL" not in os.environ:
20
+ os.environ["LOG_LEVEL"] = "INFO"
21
+
22
+
23
  def configure_logging(level=None):
24
  if level is None:
25
  level = getattr(logging, os.environ.get("LOG_LEVEL", "INFO"))
 
28
  # which includes other libraries.
29
  logging.basicConfig(
30
  level=level,
31
+ format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
32
  handlers=[
33
  logging.StreamHandler(), # Outputs logs to stderr by default
34
  # If you also want to log to a file, uncomment the following line:
35
  # logging.FileHandler('my_app.log', mode='a', encoding='utf-8')
36
+ ],
37
  )
38
 
39
 
40
+ def run_cli_command(
41
+ protein_path: str,
42
+ ligand: str,
43
+ samples_per_complex: int,
44
+ keep_local_structures: bool,
45
+ save_visualisation: bool,
46
+ work_dir=None,
47
+ ):
48
  if work_dir is None:
49
+ work_dir = os.environ.get(
50
+ "DiffDock-Pocket-Dir", os.path.join(os.environ["HOME"], "DiffDock-Pocket")
51
+ )
52
+
53
+ command = [
54
+ "python3",
55
+ "inference.py",
56
+ f"--protein_path={protein_path}",
57
+ f"--ligand={ligand}",
58
+ f"--samples_per_complex={samples_per_complex}",
59
+ ]
60
 
61
  # Adding boolean arguments only if they are True
62
  if keep_local_structures:
 
66
 
67
  with tempfile.TemporaryDirectory() as temp_dir:
68
  temp_dir_path = temp_dir
 
69
  command.append(f"--out_dir={temp_dir_path}")
70
 
71
  # Convert command list to string for printing
 
75
  # Running the command
76
  try:
77
  result = subprocess.run(
78
+ command,
79
+ cwd=work_dir,
80
+ check=False,
81
+ text=True,
82
+ capture_output=True,
83
+ env=os.environ,
84
  )
85
  logging.debug(f"Command output:\n{result.stdout}")
86
  if result.stderr:
 
94
  uuid_tag = str(uuid.uuid4())[0:8]
95
  unique_filename = f"output_{timestamp}_{uuid_tag}"
96
  zip_base_name = os.path.join("tmp", unique_filename)
97
+ full_zip_path = shutil.make_archive(zip_base_name, "zip", temp_dir)
98
 
99
  logging.debug(f"Directory '{temp_dir}' zipped to '{full_zip_path}'")
100
 
101
  return full_zip_path
102
 
103
 
104
+ if __name__ == "__main__":
105
  # Testing code
106
+ set_env_variables()
107
+ configure_logging()
108
+
109
+ work_dir = os.path.abspath("../DiffDock-Pocket")
110
  os.environ["DiffDock-Pocket-Dir"] = work_dir
111
  protein_path = os.path.join(work_dir, "example_data", "3dpf_protein.pdb")
112
  ligand = os.path.join(work_dir, "example_data", "3dpf_ligand.sdf")
113
 
114
+ run_cli_command(
115
+ protein_path,
116
+ ligand,
117
+ samples_per_complex=1,
118
+ keep_local_structures=True,
119
+ save_visualisation=True,
120
+ )