simonduerr commited on
Commit
aad52f9
·
verified ·
1 Parent(s): 9d9ebf3

Update inference_app.py

Browse files
Files changed (1) hide show
  1. inference_app.py +9 -11
inference_app.py CHANGED
@@ -18,7 +18,7 @@ import gradio as gr
18
 
19
  from gradio_molecule3d import Molecule3D
20
 
21
- def protonate_receptor_and_ligand(protein,ligand):
22
  protein_out = protein.replace(".pdb","_H.pdb")
23
  with open(protein_out, "w") as f:
24
  subprocess.run(
@@ -26,20 +26,18 @@ def protonate_receptor_and_ligand(protein,ligand):
26
  stdout=f,
27
  stderr=subprocess.DEVNULL,
28
  )
29
- ligand_out = ligand.replace(".pdb","_H.pdb")
30
- subprocess.run(["obabel", ligand, "-O", ligand_out, "-p", "7.4"])
31
 
32
 
33
  def generate_conformers(ligand, num_confs=8):
34
- mol = Chem.MolFromMolFile(
35
- ligand.replace(".pdb","_H.pdb")
36
  )
37
  mol.RemoveAllConformers()
38
  mol = Chem.AddHs(mol)
39
  AllChem.EmbedMultipleConfs(mol, numConfs=num_confs, randomSeed=1)
40
  AllChem.UFFOptimizeMoleculeConfs(mol)
41
  with Chem.SDWriter(
42
- ligand.replace(".pdb","_multiple_confs.pdb")
43
  ) as writer:
44
  for cid in range(mol.GetNumConformers()):
45
  writer.write(mol, confId=cid)
@@ -84,9 +82,9 @@ def run_docking(protein, ligand):
84
  "-r",
85
  protein.replace(".pdb","_H.pdb"),
86
  "-l",
87
- ligand.replace(".sdf","_ligand_multiple_confs.sdf"),
88
  "-o",
89
- ligand.replace(".sdf","_multiple_confs_poses.sdf"),
90
  "--center_x", # bounding box matching PoseBusters methodology
91
  str(0),
92
  "--center_y",
@@ -111,13 +109,13 @@ def run_docking(protein, ligand):
111
  )
112
  # sort the poses from the multiple conformation runs, so overall best is first
113
  poses = PandasTools.LoadSDF(
114
- ligand.replace(".sdf","_multiple_confs_poses.sdf")
115
  )
116
  poses["CNNscore"] = poses["CNNscore"].astype(float)
117
  gnina_order = poses.sort_values("CNNscore", ascending=False).reset_index(drop=True)
118
  PandasTools.WriteSDF(
119
  gnina_order,
120
- ligand.replace(".sdf","_multiple_confs_poses.sdf"),
121
  properties=list(poses.columns),
122
  )
123
  return poses["CNNscore"]
@@ -131,7 +129,7 @@ def predict (input_sequence, input_ligand,input_msa, input_protein):
131
  metrics = {"cnn_score": cnn_score}
132
  end_time = time.time()
133
  run_time = end_time - start_time
134
- return ["test_out.pdb", "test_docking_pose.sdf"], metrics, run_time
135
 
136
  with gr.Blocks() as app:
137
 
 
18
 
19
  from gradio_molecule3d import Molecule3D
20
 
21
+ def protonate_receptor_and_ligand(protein):
22
  protein_out = protein.replace(".pdb","_H.pdb")
23
  with open(protein_out, "w") as f:
24
  subprocess.run(
 
26
  stdout=f,
27
  stderr=subprocess.DEVNULL,
28
  )
 
 
29
 
30
 
31
  def generate_conformers(ligand, num_confs=8):
32
+ mol = Chem.MolFromSmiles(
33
+ ligand
34
  )
35
  mol.RemoveAllConformers()
36
  mol = Chem.AddHs(mol)
37
  AllChem.EmbedMultipleConfs(mol, numConfs=num_confs, randomSeed=1)
38
  AllChem.UFFOptimizeMoleculeConfs(mol)
39
  with Chem.SDWriter(
40
+ "ligand.sdf"
41
  ) as writer:
42
  for cid in range(mol.GetNumConformers()):
43
  writer.write(mol, confId=cid)
 
82
  "-r",
83
  protein.replace(".pdb","_H.pdb"),
84
  "-l",
85
+ "ligand.sdf",
86
  "-o",
87
+ "ligand_output.sdf",
88
  "--center_x", # bounding box matching PoseBusters methodology
89
  str(0),
90
  "--center_y",
 
109
  )
110
  # sort the poses from the multiple conformation runs, so overall best is first
111
  poses = PandasTools.LoadSDF(
112
+ "ligand_output.sdf"
113
  )
114
  poses["CNNscore"] = poses["CNNscore"].astype(float)
115
  gnina_order = poses.sort_values("CNNscore", ascending=False).reset_index(drop=True)
116
  PandasTools.WriteSDF(
117
  gnina_order,
118
+ "ligand_output.sdf",
119
  properties=list(poses.columns),
120
  )
121
  return poses["CNNscore"]
 
129
  metrics = {"cnn_score": cnn_score}
130
  end_time = time.time()
131
  run_time = end_time - start_time
132
+ return ["input_protein.pdb", "ligand_output.sdf"], metrics, run_time
133
 
134
  with gr.Blocks() as app:
135